confctl 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +11 -0
- data/.gitignore +8 -0
- data/.overcommit.yml +6 -0
- data/.rubocop.yml +67 -0
- data/.rubocop_todo.yml +5 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +2 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +674 -0
- data/README.md +522 -0
- data/Rakefile +40 -0
- data/bin/confctl +4 -0
- data/confctl.gemspec +33 -0
- data/example/.gitignore +2 -0
- data/example/README.md +38 -0
- data/example/cluster/cluster.nix +7 -0
- data/example/cluster/module-list.nix +3 -0
- data/example/cluster/nixos-machine/config.nix +15 -0
- data/example/cluster/nixos-machine/hardware.nix +4 -0
- data/example/cluster/nixos-machine/module.nix +8 -0
- data/example/cluster/vpsadminos-container/config.nix +22 -0
- data/example/cluster/vpsadminos-container/module.nix +8 -0
- data/example/cluster/vpsadminos-machine/config.nix +22 -0
- data/example/cluster/vpsadminos-machine/hardware.nix +4 -0
- data/example/cluster/vpsadminos-machine/module.nix +8 -0
- data/example/cluster/vpsfreecz-vps/config.nix +25 -0
- data/example/cluster/vpsfreecz-vps/module.nix +8 -0
- data/example/configs/confctl.nix +10 -0
- data/example/configs/swpins.nix +28 -0
- data/example/data/default.nix +5 -0
- data/example/data/ssh-keys.nix +7 -0
- data/example/environments/base.nix +13 -0
- data/example/modules/module-list.nix +13 -0
- data/example/shell.nix +11 -0
- data/example/swpins/channels/nixos-unstable.json +35 -0
- data/example/swpins/channels/vpsadminos-staging.json +35 -0
- data/lib/confctl/cli/app.rb +551 -0
- data/lib/confctl/cli/attr_filters.rb +51 -0
- data/lib/confctl/cli/cluster.rb +1248 -0
- data/lib/confctl/cli/command.rb +206 -0
- data/lib/confctl/cli/configuration.rb +296 -0
- data/lib/confctl/cli/gen_data.rb +97 -0
- data/lib/confctl/cli/generation.rb +335 -0
- data/lib/confctl/cli/log_view.rb +267 -0
- data/lib/confctl/cli/output_formatter.rb +288 -0
- data/lib/confctl/cli/swpins/base.rb +40 -0
- data/lib/confctl/cli/swpins/channel.rb +73 -0
- data/lib/confctl/cli/swpins/cluster.rb +80 -0
- data/lib/confctl/cli/swpins/core.rb +86 -0
- data/lib/confctl/cli/swpins/utils.rb +55 -0
- data/lib/confctl/cli/swpins.rb +5 -0
- data/lib/confctl/cli/tag_filters.rb +30 -0
- data/lib/confctl/cli.rb +5 -0
- data/lib/confctl/conf_cache.rb +105 -0
- data/lib/confctl/conf_dir.rb +88 -0
- data/lib/confctl/erb_template.rb +37 -0
- data/lib/confctl/exceptions.rb +3 -0
- data/lib/confctl/gcroot.rb +30 -0
- data/lib/confctl/generation/build.rb +145 -0
- data/lib/confctl/generation/build_list.rb +106 -0
- data/lib/confctl/generation/host.rb +35 -0
- data/lib/confctl/generation/host_list.rb +81 -0
- data/lib/confctl/generation/unified.rb +117 -0
- data/lib/confctl/generation/unified_list.rb +63 -0
- data/lib/confctl/git_repo_mirror.rb +79 -0
- data/lib/confctl/health_checks/base.rb +66 -0
- data/lib/confctl/health_checks/run_command.rb +179 -0
- data/lib/confctl/health_checks/systemd/properties.rb +84 -0
- data/lib/confctl/health_checks/systemd/property_check.rb +31 -0
- data/lib/confctl/health_checks/systemd/property_list.rb +20 -0
- data/lib/confctl/health_checks.rb +5 -0
- data/lib/confctl/hook.rb +35 -0
- data/lib/confctl/line_buffer.rb +53 -0
- data/lib/confctl/logger.rb +151 -0
- data/lib/confctl/machine.rb +107 -0
- data/lib/confctl/machine_control.rb +172 -0
- data/lib/confctl/machine_list.rb +108 -0
- data/lib/confctl/machine_status.rb +135 -0
- data/lib/confctl/module_options.rb +95 -0
- data/lib/confctl/nix.rb +382 -0
- data/lib/confctl/nix_build.rb +108 -0
- data/lib/confctl/nix_collect_garbage.rb +64 -0
- data/lib/confctl/nix_copy.rb +49 -0
- data/lib/confctl/nix_format.rb +124 -0
- data/lib/confctl/nix_literal_expression.rb +15 -0
- data/lib/confctl/parallel_executor.rb +43 -0
- data/lib/confctl/pattern.rb +9 -0
- data/lib/confctl/settings.rb +50 -0
- data/lib/confctl/std_line_buffer.rb +40 -0
- data/lib/confctl/swpins/change_set.rb +151 -0
- data/lib/confctl/swpins/channel.rb +62 -0
- data/lib/confctl/swpins/channel_list.rb +47 -0
- data/lib/confctl/swpins/cluster_name.rb +94 -0
- data/lib/confctl/swpins/cluster_name_list.rb +15 -0
- data/lib/confctl/swpins/core.rb +137 -0
- data/lib/confctl/swpins/deployed_info.rb +23 -0
- data/lib/confctl/swpins/spec.rb +20 -0
- data/lib/confctl/swpins/specs/base.rb +184 -0
- data/lib/confctl/swpins/specs/directory.rb +51 -0
- data/lib/confctl/swpins/specs/git.rb +135 -0
- data/lib/confctl/swpins/specs/git_rev.rb +24 -0
- data/lib/confctl/swpins.rb +17 -0
- data/lib/confctl/system_command.rb +10 -0
- data/lib/confctl/user_script.rb +13 -0
- data/lib/confctl/user_scripts.rb +41 -0
- data/lib/confctl/utils/file.rb +21 -0
- data/lib/confctl/version.rb +3 -0
- data/lib/confctl.rb +43 -0
- data/man/man8/confctl-options.nix.8 +1334 -0
- data/man/man8/confctl-options.nix.8.md +1340 -0
- data/man/man8/confctl.8 +660 -0
- data/man/man8/confctl.8.md +654 -0
- data/nix/evaluator.nix +160 -0
- data/nix/lib/default.nix +83 -0
- data/nix/lib/machine/default.nix +74 -0
- data/nix/lib/machine/info.nix +5 -0
- data/nix/lib/swpins/eval.nix +71 -0
- data/nix/lib/swpins/options.nix +94 -0
- data/nix/machines.nix +31 -0
- data/nix/modules/cluster/default.nix +459 -0
- data/nix/modules/confctl/cli.nix +21 -0
- data/nix/modules/confctl/generations.nix +84 -0
- data/nix/modules/confctl/nix.nix +28 -0
- data/nix/modules/confctl/swpins.nix +55 -0
- data/nix/modules/module-list.nix +19 -0
- data/shell.nix +42 -0
- data/template/confctl-options.nix/main.erb +45 -0
- data/template/confctl-options.nix/options.erb +15 -0
- metadata +353 -0
data/nix/evaluator.nix
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
{ jsonArg }:
|
2
|
+
let
|
3
|
+
arg = builtins.fromJSON (builtins.readFile jsonArg);
|
4
|
+
|
5
|
+
hasCorePkgs = (builtins.hasAttr "coreSwpins" arg) && (builtins.hasAttr "nixpkgs" arg.coreSwpins);
|
6
|
+
|
7
|
+
nixpkgs =
|
8
|
+
if hasCorePkgs then
|
9
|
+
import arg.coreSwpins.nixpkgs {}
|
10
|
+
else
|
11
|
+
import <nixpkgs> {};
|
12
|
+
|
13
|
+
machines = import ./machines.nix {
|
14
|
+
inherit (arg) confDir;
|
15
|
+
inherit corePkgs coreLib;
|
16
|
+
};
|
17
|
+
|
18
|
+
nameValuePairs = builtins.map (m: {
|
19
|
+
name = m.name;
|
20
|
+
value = {
|
21
|
+
inherit (m) name;
|
22
|
+
} // m.config;
|
23
|
+
}) machines;
|
24
|
+
|
25
|
+
machinesAttrs = builtins.listToAttrs nameValuePairs;
|
26
|
+
|
27
|
+
fullMachinesAttrs = builtins.listToAttrs (builtins.map (m: {
|
28
|
+
name = m.name;
|
29
|
+
value = m;
|
30
|
+
}) machines);
|
31
|
+
|
32
|
+
coreSwpins =
|
33
|
+
import ./lib/swpins/eval.nix {
|
34
|
+
inherit (arg) confDir;
|
35
|
+
name = "core";
|
36
|
+
dir = "";
|
37
|
+
channels = evalConfctl.config.confctl.swpins.core.channels;
|
38
|
+
pkgs = nixpkgs.pkgs;
|
39
|
+
lib = nixpkgs.lib;
|
40
|
+
};
|
41
|
+
|
42
|
+
corePkgs =
|
43
|
+
if hasCorePkgs then
|
44
|
+
nixpkgs
|
45
|
+
else if builtins.hasAttr "nixpkgs" coreSwpins.evaluated then
|
46
|
+
import coreSwpins.evaluated.nixpkgs {}
|
47
|
+
else
|
48
|
+
abort "Core swpins not set, run `confctl swpins core update`";
|
49
|
+
|
50
|
+
coreLib = corePkgs.lib;
|
51
|
+
|
52
|
+
machineSwpins = m:
|
53
|
+
import ./lib/swpins/eval.nix {
|
54
|
+
inherit (arg) confDir;
|
55
|
+
name = m.name;
|
56
|
+
channels = m.config.swpins.channels;
|
57
|
+
pkgs = corePkgs.pkgs;
|
58
|
+
lib = corePkgs.lib;
|
59
|
+
};
|
60
|
+
|
61
|
+
coreSwpinsAttrs = coreSwpins.evaluated;
|
62
|
+
|
63
|
+
selectedSwpinsAttrs = builtins.listToAttrs (builtins.map (host: {
|
64
|
+
name = host;
|
65
|
+
value = (machineSwpins fullMachinesAttrs.${host}).evaluated;
|
66
|
+
}) arg.machines);
|
67
|
+
|
68
|
+
selectedToplevels = builtins.listToAttrs (builtins.map (host: {
|
69
|
+
name = host;
|
70
|
+
value = buildToplevel fullMachinesAttrs.${host};
|
71
|
+
}) arg.machines);
|
72
|
+
|
73
|
+
buildToplevel = m: (evalMachine m).config.system.build.toplevel;
|
74
|
+
|
75
|
+
evalMachine = m:
|
76
|
+
let
|
77
|
+
importPath = {
|
78
|
+
nixos = <nixpkgs/nixos/lib/eval-config.nix>;
|
79
|
+
vpsadminos = <vpsadminos/os/default.nix>;
|
80
|
+
};
|
81
|
+
|
82
|
+
evalConfig = import importPath.${m.config.spin} {
|
83
|
+
modules = [ m.build.toplevel ];
|
84
|
+
};
|
85
|
+
in evalConfig;
|
86
|
+
|
87
|
+
evalConfctl =
|
88
|
+
let
|
89
|
+
cfg = "${toString arg.confDir}/configs/confctl.nix";
|
90
|
+
in evalNixosModules ([
|
91
|
+
./modules/confctl/generations.nix
|
92
|
+
./modules/confctl/cli.nix
|
93
|
+
./modules/confctl/nix.nix
|
94
|
+
./modules/confctl/swpins.nix
|
95
|
+
"${toString arg.confDir}/configs/swpins.nix"
|
96
|
+
] ++ nixpkgs.lib.optional (builtins.pathExists cfg) cfg);
|
97
|
+
|
98
|
+
docToplevels = [
|
99
|
+
"cluster."
|
100
|
+
"confctl."
|
101
|
+
];
|
102
|
+
|
103
|
+
filterOption = o:
|
104
|
+
!o.internal && builtins.any (top: nixpkgs.lib.hasPrefix top o.name) docToplevels;
|
105
|
+
|
106
|
+
docModules =
|
107
|
+
let
|
108
|
+
userModules = "${toString arg.confDir}/modules/cluster/default.nix";
|
109
|
+
in evalNixosModules (
|
110
|
+
(import ./modules/module-list.nix).all
|
111
|
+
++
|
112
|
+
(nixpkgs.lib.optional (builtins.pathExists userModules) userModules)
|
113
|
+
);
|
114
|
+
|
115
|
+
docOptions =
|
116
|
+
builtins.filter filterOption (nixpkgs.lib.optionAttrSetToDocList docModules.options);
|
117
|
+
|
118
|
+
evalNixosModules = modules:
|
119
|
+
import <nixpkgs/nixos/lib/eval-config.nix> {
|
120
|
+
modules = modules ++ [
|
121
|
+
({ ... }:
|
122
|
+
{
|
123
|
+
_module.args = {
|
124
|
+
confLib = import ./lib {
|
125
|
+
confDir = "${toString arg.confDir}";
|
126
|
+
coreLib = nixpkgs.lib;
|
127
|
+
corePkgs = nixpkgs.pkgs;
|
128
|
+
};
|
129
|
+
};
|
130
|
+
})
|
131
|
+
];
|
132
|
+
};
|
133
|
+
|
134
|
+
build = {
|
135
|
+
# confctl settings
|
136
|
+
confctl = nixpkgs.writeText "confctl-settings.json" (builtins.toJSON { confctl = evalConfctl.config.confctl; });
|
137
|
+
|
138
|
+
# List available nixos module options for documentation purposes
|
139
|
+
moduleOptions = docOptions;
|
140
|
+
|
141
|
+
# List of machines
|
142
|
+
list = { machines = builtins.map (m: m.name) machines; };
|
143
|
+
|
144
|
+
# List of machines in an attrset: host => config
|
145
|
+
info = corePkgs.writeText "machine-list.json" (builtins.toJSON machinesAttrs);
|
146
|
+
|
147
|
+
# Nix configuration of swpins channels
|
148
|
+
listSwpinsChannels = evalConfctl.config.confctl.swpins.channels;
|
149
|
+
|
150
|
+
# JSON file with core swpins
|
151
|
+
evalCoreSwpins = corePkgs.writeText "swpins.json" (builtins.toJSON coreSwpinsAttrs);
|
152
|
+
|
153
|
+
# JSON file with swpins for selected machines
|
154
|
+
evalHostSwpins = corePkgs.writeText "swpins.json" (builtins.toJSON selectedSwpinsAttrs);
|
155
|
+
|
156
|
+
# JSON file with system.build.toplevel for selected machines, this must
|
157
|
+
# be run with proper NIX_PATH with swpins
|
158
|
+
toplevel = corePkgs.writeText "toplevels.json" (builtins.toJSON selectedToplevels);
|
159
|
+
};
|
160
|
+
in build.${arg.build}
|
data/nix/lib/default.nix
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
{ confDir, coreLib, corePkgs }:
|
2
|
+
with coreLib;
|
3
|
+
let
|
4
|
+
machine = import ./machine { inherit confDir corePkgs coreLib findConfig; };
|
5
|
+
|
6
|
+
findConfig =
|
7
|
+
{ cluster, name }:
|
8
|
+
cluster.${name};
|
9
|
+
|
10
|
+
makeMachine =
|
11
|
+
{ name, config }:
|
12
|
+
{
|
13
|
+
inherit name config;
|
14
|
+
build.toplevel = buildConfig { inherit name config; };
|
15
|
+
};
|
16
|
+
|
17
|
+
buildConfig =
|
18
|
+
{ name, config }:
|
19
|
+
if !config.managed then
|
20
|
+
null
|
21
|
+
else if config.spin == "nixos" then
|
22
|
+
machine.nixos { inherit name config; }
|
23
|
+
else if config.spin == "vpsadminos" then
|
24
|
+
machine.vpsadminos { inherit name config; }
|
25
|
+
else
|
26
|
+
null;
|
27
|
+
in rec {
|
28
|
+
inherit corePkgs coreLib;
|
29
|
+
|
30
|
+
mkNetUdevRule = name: mac: ''
|
31
|
+
ACTION=="add", SUBSYSTEM=="net", DRIVERS=="?*", KERNEL=="eth*", ATTR{address}=="${mac}", NAME="${name}"
|
32
|
+
'';
|
33
|
+
|
34
|
+
mkNetUdevRules = rs: concatStringsSep "\n" (mapAttrsToList (name: mac:
|
35
|
+
mkNetUdevRule name mac
|
36
|
+
) rs);
|
37
|
+
|
38
|
+
inherit findConfig;
|
39
|
+
|
40
|
+
# Return all configured machines in a list
|
41
|
+
getClusterMachines = cluster:
|
42
|
+
mapAttrsToList (name: config:
|
43
|
+
makeMachine { inherit name config; }
|
44
|
+
) cluster;
|
45
|
+
|
46
|
+
# Get IP version addresses from all machines in a cluster
|
47
|
+
getAllAddressesOf = cluster: v:
|
48
|
+
let
|
49
|
+
machines = getClusterMachines cluster;
|
50
|
+
addresses = flatten (map (machine:
|
51
|
+
map (addr: machine // addr) machine.config.addresses.${"v${toString v}"}
|
52
|
+
) machines);
|
53
|
+
in addresses;
|
54
|
+
|
55
|
+
mkOptions = {
|
56
|
+
addresses = v:
|
57
|
+
{ config, ... }:
|
58
|
+
{
|
59
|
+
options = {
|
60
|
+
address = mkOption {
|
61
|
+
type = types.str;
|
62
|
+
description = "IPv${toString v} address";
|
63
|
+
};
|
64
|
+
|
65
|
+
prefix = mkOption {
|
66
|
+
type = types.ints.positive;
|
67
|
+
description = "Prefix length";
|
68
|
+
};
|
69
|
+
|
70
|
+
string = mkOption {
|
71
|
+
type = types.nullOr types.str;
|
72
|
+
default = null;
|
73
|
+
apply = v:
|
74
|
+
if isNull v then
|
75
|
+
"${config.address}/${toString config.prefix}"
|
76
|
+
else
|
77
|
+
v;
|
78
|
+
description = "Address with prefix as string";
|
79
|
+
};
|
80
|
+
};
|
81
|
+
};
|
82
|
+
};
|
83
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
{ confDir, corePkgs, coreLib, findConfig }:
|
2
|
+
let
|
3
|
+
swpinsFor =
|
4
|
+
{ name, config }:
|
5
|
+
import ../swpins/eval.nix {
|
6
|
+
inherit confDir name;
|
7
|
+
channels = config.swpins.channels;
|
8
|
+
pkgs = corePkgs;
|
9
|
+
lib = coreLib;
|
10
|
+
};
|
11
|
+
|
12
|
+
makeModuleArgs =
|
13
|
+
{ config, swpins, spin, name }@args: {
|
14
|
+
swpins = swpins.evaluated;
|
15
|
+
swpinsInfo = swpins.infos;
|
16
|
+
confMachine = import ./info.nix (args // { inherit findConfig; });
|
17
|
+
};
|
18
|
+
|
19
|
+
makeImports = spin: extraImports: [
|
20
|
+
({ config, pkgs, lib, confMachine, ... }:
|
21
|
+
{
|
22
|
+
_file = "confctl/nix/lib/machine/default.nix";
|
23
|
+
|
24
|
+
_module.args = {
|
25
|
+
inherit confDir;
|
26
|
+
confLib = import ../../lib { inherit confDir coreLib corePkgs; };
|
27
|
+
confData = import "${toString confDir}/data/default.nix" { inherit lib; };
|
28
|
+
};
|
29
|
+
|
30
|
+
networking.hostName =
|
31
|
+
lib.mkIf (confMachine.host != null && confMachine.host.name != null) (lib.mkDefault confMachine.host.name);
|
32
|
+
|
33
|
+
networking.domain =
|
34
|
+
lib.mkIf (confMachine.host != null) (lib.mkDefault confMachine.host.fullDomain);
|
35
|
+
})
|
36
|
+
] ++ (import ../../modules/module-list.nix).${spin}
|
37
|
+
++ (import "${toString confDir}/modules/module-list.nix").${spin}
|
38
|
+
++ (import "${toString confDir}/cluster/module-list.nix")
|
39
|
+
++ extraImports;
|
40
|
+
in rec {
|
41
|
+
nixos = { name, config }:
|
42
|
+
let
|
43
|
+
swpins = swpinsFor { inherit name config; };
|
44
|
+
in
|
45
|
+
{ config, pkgs, ... }@args:
|
46
|
+
{
|
47
|
+
_module.args = makeModuleArgs {
|
48
|
+
inherit config swpins;
|
49
|
+
spin = "nixos";
|
50
|
+
inherit name;
|
51
|
+
};
|
52
|
+
|
53
|
+
imports = makeImports "nixos" [
|
54
|
+
"${toString confDir}/cluster/${name}/config.nix"
|
55
|
+
];
|
56
|
+
};
|
57
|
+
|
58
|
+
vpsadminos = { name, config }:
|
59
|
+
let
|
60
|
+
swpins = swpinsFor { inherit name config; };
|
61
|
+
in
|
62
|
+
{ config, pkgs, ... }@args:
|
63
|
+
{
|
64
|
+
_module.args = makeModuleArgs {
|
65
|
+
inherit config swpins;
|
66
|
+
spin = "vpsadminos";
|
67
|
+
inherit name;
|
68
|
+
};
|
69
|
+
|
70
|
+
imports = makeImports "vpsadminos" [
|
71
|
+
"${toString confDir}/cluster/${name}/config.nix"
|
72
|
+
];
|
73
|
+
};
|
74
|
+
}
|
@@ -0,0 +1,71 @@
|
|
1
|
+
{ confDir, name, dir ? "cluster", channels, pkgs, lib }:
|
2
|
+
let
|
3
|
+
pinFileName = builtins.replaceStrings [ "/" ] [ ":" ] name;
|
4
|
+
|
5
|
+
pinFilePath = "${toString confDir}/swpins/${dir}/${pinFileName}.json";
|
6
|
+
|
7
|
+
pinFileJson = builtins.readFile pinFilePath;
|
8
|
+
|
9
|
+
pinFileSpecs =
|
10
|
+
if builtins.pathExists pinFilePath then
|
11
|
+
builtins.fromJSON pinFileJson
|
12
|
+
else
|
13
|
+
{};
|
14
|
+
|
15
|
+
pinFileSwpins = lib.mapAttrs (k: v: swpin v) pinFileSpecs;
|
16
|
+
|
17
|
+
channelPath = chan: "${toString confDir}/swpins/channels/${chan}.json";
|
18
|
+
|
19
|
+
channelJson = chan: builtins.readFile (channelPath chan);
|
20
|
+
|
21
|
+
channelSpecs = chan: builtins.fromJSON (channelJson chan);
|
22
|
+
|
23
|
+
channelSwpins = chan: lib.mapAttrs (k: v: swpin v) (channelSpecs chan);
|
24
|
+
|
25
|
+
allChannelSwpins = map channelSwpins channels;
|
26
|
+
|
27
|
+
allSwpins = (lib.foldl (a: b: a // b) {} allChannelSwpins) // pinFileSwpins;
|
28
|
+
|
29
|
+
swpin = { fetcher, ... }:
|
30
|
+
fetchers.${fetcher.type} fetcher.options;
|
31
|
+
|
32
|
+
fetchers = rec {
|
33
|
+
directory = opts:
|
34
|
+
opts.path;
|
35
|
+
|
36
|
+
git = opts:
|
37
|
+
let
|
38
|
+
filter = lib.filterAttrs (k: v: builtins.elem k [
|
39
|
+
"url" "rev" "sha256" "fetchSubmodules"
|
40
|
+
]);
|
41
|
+
in pkgs.fetchgit (filter opts);
|
42
|
+
|
43
|
+
zip = opts:
|
44
|
+
pkgs.fetchzip opts;
|
45
|
+
|
46
|
+
git-rev = opts:
|
47
|
+
let
|
48
|
+
repo = fetchers.${opts.wrapped_fetcher.type} opts.wrapped_fetcher.options;
|
49
|
+
shortRev = lib.substring 0 9 (opts.rev);
|
50
|
+
in
|
51
|
+
pkgs.runCommand "git-${shortRev}" {} ''
|
52
|
+
cp -a ${repo} $out
|
53
|
+
chmod 700 $out
|
54
|
+
echo "${opts.rev}" > $out/.git-revision
|
55
|
+
echo ".git.${shortRev}" > $out/.version-suffix
|
56
|
+
'';
|
57
|
+
};
|
58
|
+
|
59
|
+
pinFileInfos = lib.mapAttrs (k: v: v.info or {}) pinFileSpecs;
|
60
|
+
|
61
|
+
channelInfos = chan: lib.mapAttrs (k: v: v.info or {}) (channelSpecs chan);
|
62
|
+
|
63
|
+
allChannelInfos = map channelInfos channels;
|
64
|
+
|
65
|
+
allInfos = (lib.foldl (a: b: a // b) {} allChannelInfos) // pinFileInfos;
|
66
|
+
|
67
|
+
in {
|
68
|
+
evaluated = allSwpins;
|
69
|
+
|
70
|
+
infos = allInfos;
|
71
|
+
}
|
@@ -0,0 +1,94 @@
|
|
1
|
+
{ lib }:
|
2
|
+
with lib;
|
3
|
+
rec {
|
4
|
+
specModule =
|
5
|
+
{ config, ... }:
|
6
|
+
{
|
7
|
+
options = {
|
8
|
+
type = mkOption {
|
9
|
+
type = types.enum [ "directory" "git" "git-rev" ];
|
10
|
+
default = "git";
|
11
|
+
};
|
12
|
+
|
13
|
+
directory = mkOption {
|
14
|
+
type = types.nullOr (types.submodule directorySpec);
|
15
|
+
default = null;
|
16
|
+
};
|
17
|
+
|
18
|
+
git = mkOption {
|
19
|
+
type = types.nullOr (types.submodule gitSpec);
|
20
|
+
default = null;
|
21
|
+
};
|
22
|
+
|
23
|
+
git-rev = mkOption {
|
24
|
+
type = types.nullOr (types.submodule gitSpec);
|
25
|
+
default = null;
|
26
|
+
};
|
27
|
+
};
|
28
|
+
};
|
29
|
+
|
30
|
+
directorySpec =
|
31
|
+
{ config, ... }:
|
32
|
+
{
|
33
|
+
options = {
|
34
|
+
path = mkOption {
|
35
|
+
type = types.str;
|
36
|
+
description = ''
|
37
|
+
Absolute path to the directory
|
38
|
+
'';
|
39
|
+
example = "/opt/my-swpin";
|
40
|
+
};
|
41
|
+
};
|
42
|
+
};
|
43
|
+
|
44
|
+
gitSpec =
|
45
|
+
{ config, ... }:
|
46
|
+
{
|
47
|
+
options = {
|
48
|
+
url = mkOption {
|
49
|
+
type = types.str;
|
50
|
+
description = ''
|
51
|
+
URL of the git repository
|
52
|
+
'';
|
53
|
+
example = "https://github.com/vpsfreecz/vpsadminos";
|
54
|
+
};
|
55
|
+
|
56
|
+
fetchSubmodules = mkOption {
|
57
|
+
type = types.bool;
|
58
|
+
default = false;
|
59
|
+
description = ''
|
60
|
+
Fetch git submodules
|
61
|
+
'';
|
62
|
+
};
|
63
|
+
|
64
|
+
update = {
|
65
|
+
ref = mkOption {
|
66
|
+
type = types.nullOr types.str;
|
67
|
+
default = null;
|
68
|
+
description = ''
|
69
|
+
Implicit git reference to use for both manual and automatic updates
|
70
|
+
'';
|
71
|
+
example = "refs/heads/master";
|
72
|
+
};
|
73
|
+
|
74
|
+
auto = mkOption {
|
75
|
+
type = types.bool;
|
76
|
+
default = false;
|
77
|
+
description = ''
|
78
|
+
When enabled, the pin is automatically updated to
|
79
|
+
<literal>ref</literal> before building machines.
|
80
|
+
'';
|
81
|
+
};
|
82
|
+
|
83
|
+
interval = mkOption {
|
84
|
+
type = types.int;
|
85
|
+
default = 60*60;
|
86
|
+
description = ''
|
87
|
+
Number of seconds from the last update to trigger the next
|
88
|
+
auto-update, if auto-update is enabled.
|
89
|
+
'';
|
90
|
+
};
|
91
|
+
};
|
92
|
+
};
|
93
|
+
};
|
94
|
+
}
|
data/nix/machines.nix
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
{ confDir, corePkgs, coreLib }:
|
2
|
+
let
|
3
|
+
confLib = import ./lib { inherit confDir coreLib corePkgs; };
|
4
|
+
|
5
|
+
userModules = "${toString confDir}/modules/cluster/default.nix";
|
6
|
+
|
7
|
+
baseModules = [
|
8
|
+
({ ... }:
|
9
|
+
{
|
10
|
+
_module.args = {
|
11
|
+
pkgs = corePkgs;
|
12
|
+
inherit confLib;
|
13
|
+
swpins = {};
|
14
|
+
swpinsInfo = {};
|
15
|
+
confMachine = null;
|
16
|
+
};
|
17
|
+
})
|
18
|
+
|
19
|
+
./modules/cluster
|
20
|
+
] ++ (import "${toString confDir}/cluster/module-list.nix")
|
21
|
+
++ (coreLib.optional (builtins.pathExists userModules) userModules);
|
22
|
+
|
23
|
+
evalConfig = corePkgs.lib.evalModules {
|
24
|
+
prefix = [];
|
25
|
+
modules = baseModules;
|
26
|
+
};
|
27
|
+
|
28
|
+
cluster = evalConfig.config.cluster;
|
29
|
+
|
30
|
+
allMachines = confLib.getClusterMachines cluster;
|
31
|
+
in allMachines
|