blob: 7ab7e7147eded6f5e88cfb53dac269de49335e00 [file] [log] [blame]
Serge Bazanski48427052021-02-14 09:50:24 +00001{ hscloud, pkgs, ... }:
2
3with builtins;
Sergiusz Bazanskic78cc132020-02-02 22:31:53 +01004
5let
6 machines = (import ./defs-machines.nix);
7 configurations = builtins.listToAttrs (map (machine: {
8 name = machine.fqdn;
Serge Bazanski48427052021-02-14 09:50:24 +00009 value = pkgs.nixos ({ config, pkgs, ... }: {
Sergiusz Bazanskic78cc132020-02-02 22:31:53 +010010 networking.hostName = machine.name;
11 imports = [
Serge Bazanskifbe234b2020-10-03 00:13:28 +020012 ./modules/base.nix
13 ./modules/kubernetes.nix
Sergiusz Bazanskic78cc132020-02-02 22:31:53 +010014 ];
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 Bazanski36224c62020-10-10 14:54:09 +020025 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 Bazanskic78cc132020-02-02 22:31:53 +010035 '';
36
Serge Bazanski48427052021-02-14 09:50:24 +000037 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 Bazanskic78cc132020-02-02 22:31:53 +010045in
Serge Bazanski48427052021-02-14 09:50:24 +000046pkgs.symlinkJoin {
47 name = "provision";
48 paths = [ provision ] ++ provisioners;
Sergiusz Bazanskic78cc132020-02-02 22:31:53 +010049}