aboutsummaryrefslogtreecommitdiff
path: root/nixinate/make-deploy-script.nix
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2023-08-11 16:51:35 +0200
committerMax Audron <audron@cocaine.farm>2023-08-11 16:51:35 +0200
commit75b417455361d776d8c92a35ba69854c0cc0bcee (patch)
treecacf2223821749e372c2968fc659248b26e43c59 /nixinate/make-deploy-script.nix
parentadd custom nixinate impl (diff)
move nixinate to own flake
Diffstat (limited to 'nixinate/make-deploy-script.nix')
-rw-r--r--nixinate/make-deploy-script.nix45
1 files changed, 0 insertions, 45 deletions
diff --git a/nixinate/make-deploy-script.nix b/nixinate/make-deploy-script.nix
deleted file mode 100644
index ab128b3..0000000
--- a/nixinate/make-deploy-script.nix
+++ /dev/null
@@ -1,45 +0,0 @@
-{ nixpkgs, pkgs, flake, ... }:
-{ machine, dryRun }:
-let
- inherit (builtins) abort;
- inherit (pkgs.lib) getExe optionalString concatStringsSep;
-
- nix = "${getExe pkgs.nix}";
- nixos-rebuild = "${getExe pkgs.nixos-rebuild}";
- openssh = "${getExe pkgs.openssh}";
- flock = "${getExe pkgs.flock}";
-
- n = flake.nixosConfigurations.${machine}._module.args.nixinate;
- hermetic = n.hermetic or true;
- user = n.sshUser or "root";
- host = n.host;
- where = n.buildOn 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;
- switch = if dryRun then "dry-activate" else "switch";
- nixOptions = concatStringsSep " " (n.nixOptions or [ ]);
-
- script =
- ''
- set -e
- echo "🚀 Deploying nixosConfigurations.${machine} from ${flake}"
- echo "👤 SSH User: ${user}"
- echo "🌐 SSH Host: ${host}"
- '' + (if remote then ''
- echo "🚀 Sending flake to ${machine} via nix copy:"
- ( set -x; ${nix} ${nixOptions} copy ${flake} --to ssh://${user}@${host} )
- '' + (if hermetic then ''
- echo "🤞 Activating configuration hermetically on ${machine} via ssh:"
- ( set -x; ${nix} ${nixOptions} copy --derivation ${nixos-rebuild} ${flock} --to ssh://${user}@${host} )
- ( set -x; ${openssh} -t ${user}@${host} "sudo nix-store --realise ${nixos-rebuild} ${flock} && sudo ${flock} -w 60 /dev/shm/nixinate-${machine} ${nixos-rebuild} ${nixOptions} ${switch} --flake ${flake}#${machine}" )
- '' else ''
- echo "🤞 Activating configuration non-hermetically on ${machine} via ssh:"
- ( set -x; ${openssh} -t ${user}@${host} "sudo flock -w 60 /dev/shm/nixinate-${machine} nixos-rebuild ${switch} --flake ${flake}#${machine}" )
- '')
- else ''
- 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} ${nixos-rebuild} ${nixOptions} ${switch} --flake ${flake}#${machine} --target-host ${user}@${host} --use-remote-sudo ${optionalString substituteOnTarget "-s"} )
-
- '');
-in
-pkgs.writeScript "deploy-${machine}.sh" script