Serge Bazanski | 4842705 | 2021-02-14 09:50:24 +0000 | [diff] [blame] | 1 | { hscloud, pkgs, ... }: |
| 2 | |
| 3 | with builtins; |
Sergiusz Bazanski | c78cc13 | 2020-02-02 22:31:53 +0100 | [diff] [blame] | 4 | |
| 5 | let |
| 6 | machines = (import ./defs-machines.nix); |
| 7 | configurations = builtins.listToAttrs (map (machine: { |
| 8 | name = machine.fqdn; |
Serge Bazanski | 4842705 | 2021-02-14 09:50:24 +0000 | [diff] [blame] | 9 | value = pkgs.nixos ({ config, pkgs, ... }: { |
Sergiusz Bazanski | c78cc13 | 2020-02-02 22:31:53 +0100 | [diff] [blame] | 10 | networking.hostName = machine.name; |
| 11 | imports = [ |
Serge Bazanski | fbe234b | 2020-10-03 00:13:28 +0200 | [diff] [blame] | 12 | ./modules/base.nix |
| 13 | ./modules/kubernetes.nix |
Sergiusz Bazanski | c78cc13 | 2020-02-02 22:31:53 +0100 | [diff] [blame] | 14 | ]; |
| 15 | }); |
| 16 | }) machines); |
| 17 | |
| 18 | scriptForMachine = machine: let |
| 19 | configuration = configurations."${machine.fqdn}"; |
| 20 | in '' |
| 21 | set -e |
| 22 | remote=root@${machine.fqdn} |
| 23 | echo "Configuration for ${machine.fqdn} is ${configuration.toplevel}" |
| 24 | nix copy --no-check-sigs -s --to ssh://$remote ${configuration.toplevel} |
Serge Bazanski | 36224c6 | 2020-10-10 14:54:09 +0200 | [diff] [blame] | 25 | echo "/etc/systemd/system diff:" |
| 26 | ssh $remote diff -ur /var/run/current-system/etc/systemd/system ${configuration.toplevel}/etc/systemd/system || true |
| 27 | echo "" |
| 28 | echo "" |
| 29 | ssh $remote ${configuration.toplevel}/bin/switch-to-configuration dry-activate |
| 30 | read -p "Do you want to switch to this configuration? " -n 1 -r |
| 31 | echo |
| 32 | if [[ $REPLY =~ ^[Yy]$ ]]; then |
| 33 | ssh $remote ${configuration.toplevel}/bin/switch-to-configuration switch |
| 34 | fi |
Sergiusz Bazanski | c78cc13 | 2020-02-02 22:31:53 +0100 | [diff] [blame] | 35 | ''; |
| 36 | |
Serge Bazanski | 4842705 | 2021-02-14 09:50:24 +0000 | [diff] [blame] | 37 | provisioners = (map (machine: |
| 38 | pkgs.writeScriptBin "provision-${machine.name}" (scriptForMachine machine) |
| 39 | ) machines); |
| 40 | |
| 41 | provision = pkgs.writeScriptBin "provision" ( |
| 42 | '' |
| 43 | echo "Available provisioniers:" |
| 44 | '' + (concatStringsSep "\n" (map (machine: "echo ' provision-${machine.name}'") machines))); |
Sergiusz Bazanski | c78cc13 | 2020-02-02 22:31:53 +0100 | [diff] [blame] | 45 | in |
Serge Bazanski | 4842705 | 2021-02-14 09:50:24 +0000 | [diff] [blame] | 46 | pkgs.symlinkJoin { |
| 47 | name = "provision"; |
| 48 | paths = [ provision ] ++ provisioners; |
Sergiusz Bazanski | c78cc13 | 2020-02-02 22:31:53 +0100 | [diff] [blame] | 49 | } |