confctl 1.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.editorconfig +1 -1
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +1 -0
  5. data/CHANGELOG.md +30 -1
  6. data/README.md +4 -9
  7. data/confctl.gemspec +14 -14
  8. data/docs/carrier.md +150 -0
  9. data/lib/confctl/cli/app.rb +19 -0
  10. data/lib/confctl/cli/cluster.rb +214 -49
  11. data/lib/confctl/cli/configuration.rb +7 -2
  12. data/lib/confctl/cli/gen_data.rb +19 -1
  13. data/lib/confctl/cli/generation.rb +47 -16
  14. data/lib/confctl/generation/build.rb +42 -1
  15. data/lib/confctl/generation/build_list.rb +10 -0
  16. data/lib/confctl/generation/host.rb +9 -5
  17. data/lib/confctl/generation/host_list.rb +22 -7
  18. data/lib/confctl/generation/unified.rb +5 -0
  19. data/lib/confctl/generation/unified_list.rb +10 -0
  20. data/lib/confctl/git_repo_mirror.rb +2 -2
  21. data/lib/confctl/machine.rb +105 -11
  22. data/lib/confctl/machine_control.rb +10 -2
  23. data/lib/confctl/machine_list.rb +18 -1
  24. data/lib/confctl/machine_status.rb +51 -4
  25. data/lib/confctl/nix.rb +90 -22
  26. data/lib/confctl/nix_copy.rb +5 -5
  27. data/lib/confctl/null_logger.rb +7 -0
  28. data/lib/confctl/swpins/specs/git.rb +1 -1
  29. data/lib/confctl/swpins/specs/git_rev.rb +1 -1
  30. data/lib/confctl/system_command.rb +3 -2
  31. data/lib/confctl/version.rb +1 -1
  32. data/libexec/auto-rollback.rb +106 -0
  33. data/man/man8/confctl-options.nix.8 +165 -1
  34. data/man/man8/confctl-options.nix.8.md +165 -1
  35. data/man/man8/confctl.8 +109 -73
  36. data/man/man8/confctl.8.md +86 -55
  37. data/nix/evaluator.nix +26 -7
  38. data/nix/lib/default.nix +64 -17
  39. data/nix/lib/machine/default.nix +14 -11
  40. data/nix/lib/machine/info.nix +3 -3
  41. data/nix/modules/cluster/default.nix +162 -3
  42. data/nix/modules/confctl/carrier/base.nix +35 -0
  43. data/nix/modules/confctl/carrier/carrier-env.rb +81 -0
  44. data/nix/modules/confctl/carrier/netboot/build-netboot-server.rb +962 -0
  45. data/nix/modules/confctl/carrier/netboot/nixos.nix +185 -0
  46. data/nix/modules/confctl/kexec-netboot/default.nix +36 -0
  47. data/nix/modules/confctl/kexec-netboot/kexec-netboot.8.adoc +62 -0
  48. data/nix/modules/confctl/kexec-netboot/kexec-netboot.rb +455 -0
  49. data/nix/modules/system-list.nix +10 -0
  50. metadata +17 -7
  51. data/.ruby-version +0 -1
@@ -0,0 +1,185 @@
1
+ { config, lib, pkgs, confMachine, ... }:
2
+ let
3
+ inherit (lib) concatStringsSep flip mkOption mkEnableOption mkIf
4
+ optional optionalString types;
5
+
6
+ concatNl = concatStringsSep "\n";
7
+
8
+ cfg = config.confctl.carrier.netboot;
9
+
10
+ isoImage =
11
+ { config, ... }:
12
+ {
13
+ options = {
14
+ file = mkOption {
15
+ type = types.path;
16
+ description = ''
17
+ Path to the ISO image file
18
+
19
+ If it is a path, the file must be available on the build machine,
20
+ it will be copied into the Nix store and deployed to the target machine.
21
+ If it is a string, then the file must be available on the target machine
22
+ at the given path.
23
+ '';
24
+ };
25
+
26
+ label = mkOption {
27
+ type = types.str;
28
+ default = "";
29
+ description = "Menu label for this image";
30
+ };
31
+ };
32
+ };
33
+
34
+ baseDir = "/var/lib/confctl/carrier/netboot";
35
+
36
+ tftpRoot = "${baseDir}/tftp";
37
+
38
+ httpRoot = "${baseDir}/http";
39
+
40
+ builderConfig = builtins.toJSON {
41
+ ruby = pkgs.ruby;
42
+ coreutils = pkgs.coreutils;
43
+ syslinux = pkgs.syslinux;
44
+ inherit tftpRoot httpRoot;
45
+ hostName = config.networking.hostName;
46
+ httpUrl = "http://${cfg.host}";
47
+ memtest =
48
+ if cfg.memtest86.enable then
49
+ { package = pkgs.memtest86plus; params = cfg.memtest86.params; }
50
+ else
51
+ null;
52
+ isoImages = cfg.isoImages;
53
+ };
54
+
55
+ builder = pkgs.substituteAll {
56
+ src = ./build-netboot-server.rb;
57
+ name = "build-netboot-server";
58
+ dir = "bin";
59
+ isExecutable = true;
60
+ ruby = pkgs.ruby;
61
+ jsonConfig = pkgs.writeText "netboot-server.json" builderConfig;
62
+ };
63
+ in {
64
+ options = {
65
+ confctl.carrier.netboot = {
66
+ enable = mkEnableOption ''
67
+ Enable netboot server generated from confctl carrier
68
+ '';
69
+
70
+ host = mkOption {
71
+ type = types.str;
72
+ description = "Hostname or IP address of the netboot server";
73
+ };
74
+
75
+ enableACME = mkOption {
76
+ type = types.bool;
77
+ description = "Enable ACME and SSL for netboot host";
78
+ default = false;
79
+ };
80
+
81
+ memtest86 = {
82
+ enable = mkOption {
83
+ type = types.bool;
84
+ description = "Include memtest in boot menu";
85
+ default = true;
86
+ };
87
+
88
+ params = mkOption {
89
+ type = types.listOf types.str;
90
+ default = [];
91
+ example = [ "console=ttyS0,115200" ];
92
+ description = "See {option}`boot.loader.grub.memtest86.params`";
93
+ };
94
+ };
95
+
96
+ isoImages = mkOption {
97
+ type = types.listOf (types.submodule isoImage);
98
+ default = [];
99
+ description = "A list of ISO images to be included in boot menu";
100
+ };
101
+
102
+ allowedIPv4Ranges = mkOption {
103
+ type = types.listOf types.str;
104
+ description = ''
105
+ Allow HTTP access for these IP ranges, if not specified
106
+ access is not restricted.
107
+ '';
108
+ default = [];
109
+ example = "10.0.0.0/24";
110
+ };
111
+
112
+ tftp.bindAddress = mkOption {
113
+ type = types.nullOr types.str;
114
+ default = null;
115
+ description = ''
116
+ The address for the TFTP server to bind on
117
+ '';
118
+ };
119
+ };
120
+ };
121
+
122
+ config = mkIf cfg.enable {
123
+ confctl.carrier.onChangeCommands = ''
124
+ ${builder}/bin/build-netboot-server
125
+ rc=$?
126
+
127
+ if [ $rc != 0 ] ; then
128
+ echo "build-netboot-server failed with $rc"
129
+ exit 1
130
+ fi
131
+ '';
132
+
133
+ environment.systemPackages = [ builder ];
134
+
135
+ networking.firewall = {
136
+ extraCommands = mkIf (cfg.allowedIPv4Ranges != []) (concatNl (map (net: ''
137
+ # Allow access from ${net} for netboot
138
+ iptables -A nixos-fw -p udp -s ${net} ${optionalString (!isNull cfg.tftp.bindAddress) "-d ${cfg.tftp.bindAddress}"} --dport 68 -j nixos-fw-accept
139
+ iptables -A nixos-fw -p udp -s ${net} ${optionalString (!isNull cfg.tftp.bindAddress) "-d ${cfg.tftp.bindAddress}"} --dport 69 -j nixos-fw-accept
140
+ iptables -A nixos-fw -p tcp -s ${net} --dport 80 -j nixos-fw-accept
141
+ ${optionalString cfg.enableACME "iptables -A nixos-fw -p tcp -s ${net} --dport 443 -j nixos-fw-accept"}
142
+ '') cfg.allowedIPv4Ranges));
143
+ };
144
+
145
+ systemd.services.netboot-atftpd = {
146
+ description = "TFTP Server for Netboot";
147
+ after = [ "network.target" ];
148
+ wantedBy = [ "multi-user.target" ];
149
+ # runs as nobody
150
+ serviceConfig.ExecStart = toString ([
151
+ "${pkgs.atftp}/sbin/atftpd"
152
+ "--daemon"
153
+ "--no-fork"
154
+ ] ++ (optional (!isNull cfg.tftp.bindAddress) [ "--bind-address" cfg.tftp.bindAddress ])
155
+ ++ [ tftpRoot ]);
156
+ };
157
+
158
+ services.nginx = {
159
+ enable = true;
160
+
161
+ appendConfig = ''
162
+ worker_processes auto;
163
+ '';
164
+
165
+ virtualHosts = {
166
+ "${cfg.host}" = {
167
+ root = httpRoot;
168
+ addSSL = cfg.enableACME;
169
+ enableACME = cfg.enableACME;
170
+ locations = {
171
+ "/" = {
172
+ extraConfig = ''
173
+ autoindex on;
174
+ ${optionalString (cfg.allowedIPv4Ranges != []) ''
175
+ ${concatNl (flip map cfg.allowedIPv4Ranges (range: "allow ${range};"))}
176
+ deny all;
177
+ ''}
178
+ '';
179
+ };
180
+ };
181
+ };
182
+ };
183
+ };
184
+ };
185
+ }
@@ -0,0 +1,36 @@
1
+ { config, lib, pkgs, confMachine, ... }:
2
+ let
3
+ inherit (lib) mkEnableOption mkIf;
4
+
5
+ cfg = config.confctl.programs.kexec-netboot;
6
+
7
+ kexecNetboot = pkgs.substituteAll {
8
+ name = "kexec-netboot";
9
+ src = ./kexec-netboot.rb;
10
+ isExecutable = true;
11
+ ruby = pkgs.ruby;
12
+ kexecTools = pkgs.kexec-tools;
13
+ machineFqdn = confMachine.host.fqdn;
14
+ };
15
+
16
+ kexecNetbootBin = pkgs.runCommand "kexec-netboot-bin" {} ''
17
+ mkdir -p $out/bin
18
+ ln -s ${kexecNetboot} $out/bin/kexec-netboot
19
+
20
+ mkdir -p $out/share/man/man8
21
+ ${pkgs.asciidoctor}/bin/asciidoctor \
22
+ -b manpage \
23
+ -D $out/share/man/man8 \
24
+ ${./kexec-netboot.8.adoc}
25
+ '';
26
+ in {
27
+ options = {
28
+ confctl.programs.kexec-netboot = {
29
+ enable = mkEnableOption "Enable kexec-netboot utility";
30
+ };
31
+ };
32
+
33
+ config = mkIf cfg.enable {
34
+ environment.systemPackages = [ kexecNetbootBin ];
35
+ };
36
+ }
@@ -0,0 +1,62 @@
1
+ = kexec-netboot(8)
2
+ :doctype: manpage
3
+ :docdate: 2025-03-03
4
+ :manmanual: kexec-netboot
5
+ :mansource: kexec-netboot
6
+ :man-linkstyle: pass:[blue R < >]
7
+
8
+ == Name
9
+
10
+ kexec-netboot - Prepare machine for kexec using kernel/initrd from netboot server
11
+
12
+ == Synopsis
13
+
14
+ *kexec-netboot* [_options_]
15
+
16
+ == Description
17
+
18
+ *kexec-netboot* may be used to download kernel and initrd from the netboot server
19
+ the machine was booted from and load it using *kexec*.
20
+
21
+ It is possible to boot into any machine available on the netboot server
22
+ and to select generation and variant (default, single-user mode).
23
+
24
+ == Options
25
+
26
+ The following options are understood:
27
+
28
+ *-h*, *--help*::
29
+ Print a short help text and exit.
30
+
31
+ *-s*, *--server-url* _URL_::
32
+ Specify URL to the netboot server. By default, the URL is auto-detected
33
+ by reading *httproot* from */proc/cmdline*.
34
+
35
+ *-m*, *--machine* _FQDN_::
36
+ Select machine from the netboot server.
37
+
38
+ *-g*, *--generation* _GENERATION_::
39
+ Select machine generation identified by its number.
40
+
41
+ *-v*, *--variant* _VARIANT_::
42
+ Select generation variant identified by its name.
43
+
44
+ *-i*, *--interactive*::
45
+ Ask the user to select machine, generation and variant interactively.
46
+
47
+ *-a*, *--append* _PARAMS_::
48
+ Append parameters to the kernel command line.
49
+
50
+ *-u*, *--unload*::
51
+ Unload the current kexec target kernel and exit.
52
+
53
+ *-e*, *--exec*::
54
+ Run the currently loaded kernel.
55
+
56
+ == Bugs
57
+
58
+ Report bugs to https://github.com/vpsfreecz/confctl/issues.
59
+
60
+ == About
61
+
62
+ *kexec-netboot* is a part of https://github.com/vpsfreecz/confctl[confctl].