-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-rs-plus.nix
More file actions
156 lines (150 loc) · 4.58 KB
/
deploy-rs-plus.nix
File metadata and controls
156 lines (150 loc) · 4.58 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
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
{config, inputs, lib, withSystem, ...}: let
inherit (lib) mkOption types;
inherit (inputs) deploy-rs;
cfg = config.deploy;
nodeSettings = { name, config, ... }: {
options.modules = mkOption {
# types.deferredModule causes some
# options to be ignored, still need to debug further
type = types.listOf types.deferredModule;
default = [];
};
options.system = mkOption {
type = types.str;
};
options.pkgs = mkOption {
type = types.nullOr types.raw;
default = null;
};
options.specialArgs = mkOption {
type = types.attrsOf types.anything;
default = {};
};
options.builder = mkOption {
type = types.functionTo types.raw;
};
options.builderInput = mkOption {
type = types.package;
};
options.builderArgs = mkOption {
type = types.attrsOf types.anything;
};
options.outputName = mkOption {
type = types.str;
};
options.output = mkOption {
type = types.raw;
};
options.pathBuilder = mkOption {
type = types.functionTo types.path;
};
config = {
modules = lib.mkIf (config.pkgs != null) [
{
nixpkgs.pkgs = config.pkgs;
nixpkgs.hostPlatform = lib.mkDefault config.pkgs.system;
}
];
output = config.builder config.builderArgs;
profiles.system = {
path = config.pathBuilder config.output;
};
hostname = lib.mkDefault (config.output.config.networking.hostname or name);
};
};
deploySettings = { config, ... }: {
options.nodeDefaults = mkOption {
type = types.deferredModule;
default = {};
};
options.nodes = mkOption {
type = types.attrsOf (types.submoduleWith {
modules = [
config.nodeDefaults
nodeSettings
{
options.class = lib.mkOption {
type = types.enum config.supportedClasses;
};
}
];
});
};
options.supportedClasses = lib.mkOption {
type = types.listOf types.str;
};
config.supportedClasses = [ "nixos" "darwin" "system" ];
options.useFlakePkgs = lib.mkEnableOption ''
set the default `pkgs` setting for each node to be
the flake's pkgs module argument.
'';
options.usePkgsDeploy = lib.mkEnableOption ''
use deploy-rs from pkgs module argument so
deploy-rs binary can be pulled from nixpkgs binary cache.
'';
};
flakeOutputs = lib.foldlAttrs (acc: nodeName: node: acc // {
${node.outputName} = (acc.${node.outputName} or {}) // {
${nodeName} = node.output;
};
}) {} config.deploy.nodes;
in {
options.deploy = mkOption {
type = types.submoduleWith {
modules = [deploySettings];
};
};
config = {
flake = flakeOutputs;
deploy.lib = lib.mkIf cfg.usePkgsDeploy (
lib.genAttrs config.systems (system:
withSystem system ({ pkgs, ... }: (pkgs.appendOverlays [
cfg.input.overlays.default
(final: prev: {
deploy-rs = {
inherit (pkgs) deploy-rs;
inherit (prev.deploy-rs) lib;
};
})
]).deploy-rs.lib)
)
);
deploy.nodeDefaults = { config, ... }: lib.mkMerge [
{
pkgs = lib.mkIf cfg.useFlakePkgs (withSystem config.system (
{ pkgs, ... }: lib.mkDefault pkgs
));
}
(lib.mkIf (config.class == "nixos") {
outputName = "nixosConfigurations";
builderInput = lib.mkIf (inputs ? nixpkgs) inputs.nixpkgs;
builder = config.builderInput.lib.nixosSystem;
builderArgs = {
inherit (config) modules system specialArgs;
};
pathBuilder = cfg.lib.${config.system}.activate.nixos;
})
(lib.mkIf (config.class == "darwin") {
outputName = "darwinConfigurations";
builderInput = lib.mkIf
(inputs ? darwin || inputs ? nix-darwin)
(inputs.darwin or inputs.nix-darwin);
builder = config.builderInput.lib.darwinSystem;
builderArgs = {
inherit (config) modules specialArgs;
};
pathBuilder = cfg.lib.${config.system}.activate.darwin;
})
(lib.mkIf (config.class == "system") {
outputName = "systemConfigs";
builderInput = lib.mkIf (inputs ? system-manager) inputs.system-manager;
builder = config.builderInput.lib.makeSystemConfig;
builderArgs = {
inherit (config) modules;
extraSpecialArgs = config.specialArgs;
};
pathBuilder = c: cfg.lib.${config.system}.activate.custom c "sudo $PROFILE/bin/activate";
})
];
};
}