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