zaphyra's git: nixfiles

zaphyra's nixfiles

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
{
  systemConfig ? null,
  lib,
  writeShellScriptBin,
  coreutils,
  openssh,
  nix,
}:

if systemConfig != null then
  writeShellScriptBin "deploySystem-${systemConfig.networking.hostName}" ''
    set -euo pipefail

    export PATH=${
      lib.makeBinPath [
        coreutils
        openssh
        nix
      ]
    }

    export NIX_SSHOPTS="''${NIX_SSHOPTS:=""} -p${toString (lib.head systemConfig.services.openssh.ports)}"

    if [[ `uname -n` != '${systemConfig.networking.hostName}' ]];
    then
      nix copy --no-check-sigs --to 'ssh-ng://root@${systemConfig.networking.fqdn}?compress=1' ${systemConfig.system.build.toplevel}
    fi

    ssh -t $NIX_SSHOPTS root@${systemConfig.networking.fqdn} "nix-env -p /nix/var/nix/profiles/system -i ${systemConfig.system.build.toplevel}"
    ssh -t $NIX_SSHOPTS root@${systemConfig.networking.fqdn} "/nix/var/nix/profiles/system/bin/switch-to-configuration ''${1:-"switch"}" 
  ''
else
  writeShellScriptBin "deploySystem-none" "echo 'No system config given!'"