forked from hswaw/hscloud
This unifies nixpkgs with the one defined in //default.nix and makes it possible to use readTree to build the provisioners: nix-build -A cluster.nix.provision result/bin/provision Change-Id: I68dd70b9c8869c7c0b59f5007981eac03667b862
49 lines
1.5 KiB
Nix
49 lines
1.5 KiB
Nix
{ hscloud, pkgs, ... }:
|
|
|
|
with builtins;
|
|
|
|
let
|
|
machines = (import ./defs-machines.nix);
|
|
configurations = builtins.listToAttrs (map (machine: {
|
|
name = machine.fqdn;
|
|
value = pkgs.nixos ({ config, pkgs, ... }: {
|
|
networking.hostName = machine.name;
|
|
imports = [
|
|
./modules/base.nix
|
|
./modules/kubernetes.nix
|
|
];
|
|
});
|
|
}) machines);
|
|
|
|
scriptForMachine = machine: let
|
|
configuration = configurations."${machine.fqdn}";
|
|
in ''
|
|
set -e
|
|
remote=root@${machine.fqdn}
|
|
echo "Configuration for ${machine.fqdn} is ${configuration.toplevel}"
|
|
nix copy --no-check-sigs -s --to ssh://$remote ${configuration.toplevel}
|
|
echo "/etc/systemd/system diff:"
|
|
ssh $remote diff -ur /var/run/current-system/etc/systemd/system ${configuration.toplevel}/etc/systemd/system || true
|
|
echo ""
|
|
echo ""
|
|
ssh $remote ${configuration.toplevel}/bin/switch-to-configuration dry-activate
|
|
read -p "Do you want to switch to this configuration? " -n 1 -r
|
|
echo
|
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|
ssh $remote ${configuration.toplevel}/bin/switch-to-configuration switch
|
|
fi
|
|
'';
|
|
|
|
provisioners = (map (machine:
|
|
pkgs.writeScriptBin "provision-${machine.name}" (scriptForMachine machine)
|
|
) machines);
|
|
|
|
provision = pkgs.writeScriptBin "provision" (
|
|
''
|
|
echo "Available provisioniers:"
|
|
'' + (concatStringsSep "\n" (map (machine: "echo ' provision-${machine.name}'") machines)));
|
|
in
|
|
pkgs.symlinkJoin {
|
|
name = "provision";
|
|
paths = [ provision ] ++ provisioners;
|
|
}
|