Repository navigation
Expand file tree
/
Copy pathmodule.nix
More file actions
118 lines (105 loc) · 3.27 KB
/
Copy pathmodule.nix
File metadata and controls
118 lines (105 loc) · 3.27 KB
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
{
config,
lib,
pkgs,
...
}:
let
cfg = config.deploy-sh;
vars = {
inherit (cfg)
buildHost
targetHost
buildCache
pushDerivations
systemCopyStrategy
;
systemDrv = config.system.build.toplevel.drvPath;
system = config.system.build.toplevel.outPath;
nomDrv = pkgs.nix-output-monitor.drvPath;
nom = pkgs.nix-output-monitor.outPath;
useSudo = if cfg.useSudo then "1" else "0";
};
text = lib.concatStringsSep "" (
lib.mapAttrsToList (k: v: "local ${k}=${lib.escapeShellArg v}\n") vars
);
in
{
options.deploy-sh = {
targetHost = lib.mkOption {
type = lib.types.str;
example = "root@10.13.37.2";
description = ''
The host to deploy the system on.
Both the local host and the build host have to be able to connect to this host via SSH.
If `systemCopyStrategy` is set to `via-local`, only the local host has to be able to connect.
'';
};
buildHost = lib.mkOption {
type = lib.types.nullOr lib.types.str;
defaultText = lib.literalExpression "config.deploy-sh.targetHost";
example = "root@10.13.37.3";
description = ''
The host to build the system on.
The local host has to be able to connect to this host via SSH.
'';
};
buildCache = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "/var/cache/deploy-sh/HOSTNAME";
description = ''
A path on the build host where to store a symlink to the new system to avoid garbage collection.
'';
};
useSudo = lib.mkOption {
type = lib.types.bool;
default = false;
example = true;
description = ''
Whether to use sudo for commands that require privileges on the target host.
'';
};
systemCopyStrategy = lib.mkOption {
type = lib.types.enum [
"direct"
"via-local"
];
default = "direct";
example = "via-local";
description = ''
How to copy the new system from the build host to the target host.
- `direct`: The build host connects directly to the target host via SSH.
- `via-local`: The system is first copied to the local host and then from there to the target host. No direct connection between build host and target host is required for this.
'';
};
enableDiff = lib.mkOption {
type = lib.types.bool;
default = true;
example = false;
description = ''
Whether to enable diffs between old and new configurations using the `--diff` and `--nvd` options.
'';
};
pushDerivations = lib.mkOption {
type = lib.types.bool;
defaultText = lib.literalExpression "config.deploy-sh.enableDiff";
description = ''
Whether to copy the system `*.drv` files to the target host.
Required for diffs to work if `buildHost != targetHost`.
'';
};
_config = lib.mkOption {
visible = false;
readOnly = true;
};
};
config = {
deploy-sh = {
buildHost = lib.mkDefault cfg.targetHost;
pushDerivations = lib.mkDefault cfg.enableDiff;
_config = pkgs.writeText "deploy-sh-config" (builtins.unsafeDiscardStringContext text);
};
nix.settings.keep-derivations = lib.mkIf cfg.enableDiff true;
};
}