Merge pull request #26 from MagicRB/master

Add options to specify Nix options
This commit is contained in:
MatthewCroughan 2022-09-26 16:27:52 +01:00 committed by GitHub
commit efa6324180
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -27,7 +27,7 @@
validMachines = final.lib.remove "" (final.lib.forEach machines (x: final.lib.optionalString (flake.nixosConfigurations."${x}"._module.args ? nixinate) "${x}" )); validMachines = final.lib.remove "" (final.lib.forEach machines (x: final.lib.optionalString (flake.nixosConfigurations."${x}"._module.args ? nixinate) "${x}" ));
mkDeployScript = { machine, dryRun }: let mkDeployScript = { machine, dryRun }: let
inherit (builtins) abort; inherit (builtins) abort;
inherit (final.lib) getExe optionalString; inherit (final.lib) getExe optionalString concatStringsSep;
nix = "${getExe final.nix}"; nix = "${getExe final.nix}";
nixos-rebuild = "${getExe final.nixos-rebuild}"; nixos-rebuild = "${getExe final.nixos-rebuild}";
openssh = "${getExe final.openssh}"; openssh = "${getExe final.openssh}";
@ -40,6 +40,8 @@
remote = if where == "remote" then true else if where == "local" then false else abort "_module.args.nixinate.buildOn is not set to a valid value of 'local' or 'remote'"; remote = if where == "remote" then true else if where == "local" then false else abort "_module.args.nixinate.buildOn is not set to a valid value of 'local' or 'remote'";
substituteOnTarget = n.substituteOnTarget or false; substituteOnTarget = n.substituteOnTarget or false;
switch = if dryRun then "dry-activate" else "switch"; switch = if dryRun then "dry-activate" else "switch";
nixOptions = concatStringsSep " " (n.nixOptions or []);
script = script =
'' ''
set -e set -e
@ -48,18 +50,19 @@
echo "🌐 SSH Host: ${host}" echo "🌐 SSH Host: ${host}"
'' + (if remote then '' '' + (if remote then ''
echo "🚀 Sending flake to ${machine} via nix copy:" echo "🚀 Sending flake to ${machine} via nix copy:"
( set -x; ${nix} copy ${flake} --to ssh://${user}@${host} ) ( set -x; ${nix} ${nixOptions} copy ${flake} --to ssh://${user}@${host} )
'' + (if hermetic then '' '' + (if hermetic then ''
echo "🤞 Activating configuration hermetically on ${machine} via ssh:" echo "🤞 Activating configuration hermetically on ${machine} via ssh:"
( set -x; ${nix} copy --derivation ${nixos-rebuild} --to ssh://${user}@${host} ) ( set -x; ${nix} ${nixOptions} copy --derivation ${nixos-rebuild} --to ssh://${user}@${host} )
( set -x; ${openssh} -t ${user}@${host} "sudo flock -w 60 /dev/shm/nixinate-${machine} -c 'nix-store --realise ${nixos-rebuild} && sudo ${nixos-rebuild} ${switch} --flake ${flake}#${machine}'" ) ( set -x; ${openssh} -t ${user}@${host} "sudo flock -w 60 /dev/shm/nixinate-${machine} -c 'nix-store --realise ${nixos-rebuild} && sudo ${nixos-rebuild} ${nixOptions} ${switch} --flake ${flake}#${machine}'" )
'' else '' '' else ''
echo "🤞 Activating configuration non-hermetically on ${machine} via ssh:" echo "🤞 Activating configuration non-hermetically on ${machine} via ssh:"
( set -x; ${openssh} -t ${user}@${host} "sudo flock -w 60 /dev/shm/nixinate-${machine} -c 'nixos-rebuild ${switch} --flake ${flake}#${machine}'" ) ( set -x; ${openssh} -t ${user}@${host} "sudo flock -w 60 /dev/shm/nixinate-${machine} -c 'nixos-rebuild ${switch} --flake ${flake}#${machine}'" )
'') '')
else '' else ''
echo "🔨 Building system closure locally, copying it to remote store and activating it:" echo "🔨 Building system closure locally, copying it to remote store and activating it:"
( set -x; NIX_SSHOPTS="-t" flock -w 60 /dev/shm/nixinate-${machine} -c '${nixos-rebuild} ${switch} --flake ${flake}#${machine} --target-host ${user}@${host} --use-remote-sudo ${optionalString substituteOnTarget "-s"}' ) ( set -x; NIX_SSHOPTS="-t" flock -w 60 /dev/shm/nixinate-${machine} -c '${nixos-rebuild} ${nixOptions} ${switch} --flake ${flake}#${machine} --target-host ${user}@${host} --use-remote-sudo ${optionalString substituteOnTarget "-s"}' )
''); '');
in final.writeScript "deploy-${machine}.sh" script; in final.writeScript "deploy-${machine}.sh" script;
in in