Skip to content

Commit 84c6ec3

Browse files
Pacman99Scrumplex
andcommitted
feat: add deploy-rs module
Based on serokell/deploy-rs#269 with changes to allow for plugin modules Co-Authored-By: Sefa Eyeoglu <[email protected]>
1 parent f2e609c commit 84c6ec3

File tree

2 files changed

+155
-0
lines changed

2 files changed

+155
-0
lines changed

deploy-rs.nix

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# SPDX-FileCopyrightText: 2024 Sefa Eyeoglu <[email protected]>
2+
# SPDX-License-Identifier: MPL-2.0
3+
4+
{config, self, inputs, lib, ...}: let
5+
inherit (lib) mkOption types;
6+
inherit (inputs) deploy-rs;
7+
8+
cfg = config.deploy;
9+
10+
settings = {
11+
generic = {
12+
options = {
13+
sshUser = mkOption {
14+
type = with types; nullOr str;
15+
default = null;
16+
};
17+
user = mkOption {
18+
type = with types; nullOr str;
19+
default = null;
20+
};
21+
sshOpts = mkOption {
22+
type = with types; listOf str;
23+
default = [];
24+
};
25+
fastConnection = mkOption {
26+
type = with types; nullOr bool;
27+
default = null;
28+
};
29+
autoRollback = mkOption {
30+
type = with types; nullOr bool;
31+
default = null;
32+
};
33+
confirmTimeout = mkOption {
34+
type = with types; nullOr int;
35+
default = null;
36+
};
37+
activationTimeout = mkOption {
38+
type = with types; nullOr int;
39+
default = null;
40+
};
41+
tempPath = mkOption {
42+
type = with types; nullOr str;
43+
default = null;
44+
};
45+
magicRollback = mkOption {
46+
type = with types; nullOr bool;
47+
default = null;
48+
};
49+
sudo = mkOption {
50+
type = with types; nullOr str;
51+
default = null;
52+
};
53+
remoteBuild = mkOption {
54+
type = with types; nullOr bool;
55+
default = null;
56+
};
57+
interactiveSudo = mkOption {
58+
type = with types; nullOr bool;
59+
default = null;
60+
};
61+
};
62+
};
63+
profile = {
64+
options = {
65+
path = mkOption {
66+
type = types.package;
67+
};
68+
profilePath = mkOption {
69+
type = with types; nullOr str;
70+
default = null;
71+
};
72+
};
73+
};
74+
node = {
75+
options = {
76+
hostname = mkOption {
77+
type = types.str;
78+
};
79+
profilesOrder = mkOption {
80+
type = with types; listOf str;
81+
default = [];
82+
};
83+
profiles = mkOption {
84+
type = types.attrsOf profileModule;
85+
};
86+
};
87+
};
88+
89+
nodes = {
90+
options.nodes = mkOption {
91+
type = types.attrsOf nodeModule;
92+
};
93+
};
94+
};
95+
96+
profileModule = types.submoduleWith {
97+
modules = [settings.generic settings.profile];
98+
};
99+
100+
nodeModule = types.submoduleWith {
101+
modules = [settings.generic settings.node];
102+
};
103+
104+
rootModule = types.submoduleWith {
105+
modules = [
106+
settings.generic
107+
settings.nodes
108+
({ config, ... }: {
109+
options.input = mkOption {
110+
type = types.package;
111+
};
112+
options.lib = mkOption {
113+
type = types.raw;
114+
};
115+
config.input = lib.mkIf
116+
(inputs ? deploy-rs || inputs ? deploy)
117+
(lib.mkDefault (inputs.deploy-rs or inputs.deploy));
118+
config.lib = lib.mkDefault config.input.lib;
119+
})
120+
];
121+
};
122+
123+
keepAttrs = attrs: names:
124+
lib.filterAttrs (name: _:
125+
lib.elem name names
126+
) attrs;
127+
128+
keepOptions = attrs: opts:
129+
keepAttrs attrs
130+
(lib.attrNames (settings.generic.options // opts.options));
131+
132+
filterNullRecursive = lib.filterAttrsRecursive (_: v: v != null);
133+
134+
in {
135+
options.deploy = mkOption {
136+
type = rootModule;
137+
};
138+
config = {
139+
flake.deploy =
140+
filterNullRecursive
141+
((keepOptions cfg settings.nodes) // {
142+
nodes = lib.mapAttrs (_: node:
143+
(keepOptions node settings.node) // {
144+
profiles = lib.mapAttrs (_: profile:
145+
keepOptions profile settings.profile
146+
) node.profiles;
147+
}
148+
) cfg.nodes;
149+
});
150+
perSystem = {system, ...}: {
151+
checks = lib.mkIf (cfg.lib ? ${system}) (cfg.lib.${system}.deployChecks self.deploy);
152+
};
153+
};
154+
}

flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
outputs = { ... }: {
33
flakeModules = {
44
tools = ./tools.nix;
5+
deploy-rs = ./deploy-rs.nix;
56
};
67
};
78
}

0 commit comments

Comments
 (0)