-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmodule.nix
208 lines (175 loc) · 5.76 KB
/
module.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.lollypops;
secret-file = types.submodule ({ config, ... }: {
options = {
name = mkOption {
type = types.str;
default = config._module.args.name;
description = "Name of the secret";
defaultText = "<name>";
};
cmd = mkOption {
type = types.str;
default = "${cfg.secrets.default-cmd} ${cfg.secrets.cmd-name-prefix}${config.name}";
description = "Command to print the secret. E.g. `cat mysecretfile`";
defaultText = "<default-cmd> <cmd-name-prefix><name>";
};
path = mkOption {
type = types.str;
default = "${cfg.secrets.default-dir}/${config.name}";
description = "Path to place the secret file";
defaultText = "<default-dir>/<name>";
};
mode = mkOption {
type = types.str;
default = "0400";
description = "Unix permission";
};
owner = mkOption {
type = types.str;
default = "root";
description = "Owner of the secret file";
};
group-name = mkOption {
type = types.str;
default = "root";
description = "Group of the secret file";
};
};
});
in
{
options.lollypops = {
secrets = {
default-cmd = mkOption {
type = types.str;
default = "${pkgs.pass}/bin/pass";
description = "Default command to retrieve passwords. Will be passed the name as parameter";
defaultText = "\${pkgs.pass}/bin/pass";
};
cmd-name-prefix = mkOption {
type = types.str;
default = "";
description = "Prefix to prepend to all name when passing to the cmd";
};
default-dir = mkOption {
type = types.str;
default = "/var/src/lollypops-secrets";
description = "Path to place the secrets on the remote host if no alternative is specified";
};
files = mkOption {
type = with types; attrsOf secret-file;
default = { };
description = "Attribute set specifying secrets to be deployed";
};
};
deployment = {
local-evaluation = mkOption {
type = types.bool;
default = false;
description = "Evaluate locally instead of on the remote when rebuilding";
};
deploy-method = mkOption {
type = types.enum [ "copy" "archive" ];
default = "copy";
description = ''
Method for copying flake to the remote. Using the default (`copy`) will
only deploy the flake itself, while `archive` deploys the flake and
all it's inputs to the remote machine. This is slower when deploying
from a connection with slow upload speed, but allows using inputs
which are not accessible from the remote.
When using `copy` all inputs of the flake will be substituted or
pulled from configured caches.
'';
};
config-dir = mkOption {
type = types.str;
default = "/var/src/lollypops";
description = "Path to place the configuration on the remote host";
};
group = mkOption {
type = types.str;
default = "default";
description = "Group name for the host, used to perform actions against a group of servers";
};
sudo = {
enable = mkOption {
type = types.bool;
default = false;
description = "Enables the use of sudo for deployment on remote servers";
};
command = mkOption {
type = types.str;
default = "sudo";
description = "Command to run for permission elevation";
};
opts = mkOption {
type = types.listOf types.str;
default = [ "" ];
example = [ "--user=user" ];
description = "Options to pass to the configured sudo command";
};
};
ssh = {
command = mkOption {
type = types.str;
default = "ssh";
description = "Command to run for connection to another server";
};
opts = mkOption {
type = types.listOf types.str;
default = [ "" ];
example = [ "-A" ];
description = "Options to pass to the configured SSH command";
};
host = mkOption {
type = types.str;
default = "${config.networking.hostName}";
description = "Host to deploy to";
};
user = mkOption {
type = types.str;
default = "root";
description = "User to deploy as";
};
};
};
tasks = mkOption {
type = types.listOf types.str;
default = [ "deploy-flake" "deploy-secrets" "rebuild" ];
description = "The list of tasks to run for each host.";
};
extraTasks = mkOption {
type = types.attrsOf (types.submodule {
options = {
dir = mkOption {
type = types.either types.path types.str;
default = ".";
description = "Directory in which the task should run.";
};
deps = mkOption {
type = types.listOf types.str;
default = [ ];
description = "Dependencies for the task.";
};
desc = mkOption {
type = types.str;
description = "Description for the task.";
};
cmds = mkOption {
type = types.listOf types.str;
description = "Commands for the task.";
};
};
});
default = { };
description = ''
Extra tasks to run for the host. If any are defined with the same name as the default tasks
(<literal>deploy-secrets</literal>, <literal>rebuild</literal>, <literal>deploy-flake</literal>)
the original tasks will be overriden.
'';
};
};
}