blob: 20ed0a0936a9e223900da87745f713ff9f76a4f7 [file] [log] [blame]
Sergiusz Bazanskic78cc132020-02-02 22:31:53 +01001self: super:
2
3let
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 Bazanskifbe234b2020-10-03 00:13:28 +020010 ./modules/base.nix
11 ./modules/kubernetes.nix
Sergiusz Bazanskic78cc132020-02-02 22:31:53 +010012 ];
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 Bazanski36224c62020-10-10 14:54:09 +020023 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 Bazanskic78cc132020-02-02 22:31:53 +010033 '';
34
35 machineProvisioners = builtins.listToAttrs (map (machine: {
36 name = "provision-${machine.name}";
37 value = super.writeScriptBin "provision-${machine.name}" (scriptForMachine machine);
38 }) machines);
39in
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}