From b5683029f90759425ee919afa359e618f57f127b Mon Sep 17 00:00:00 2001 From: Magic_RB Date: Tue, 7 Jun 2022 23:19:09 +0200 Subject: [PATCH] Add option to substitute on the target machine if local build Signed-off-by: Magic_RB Co-authored-by: matthewcroughan --- README.md | 8 ++++++++ flake.nix | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 74f032e..4aadffb 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Below is a minimal example: host = "itchy.scratchy.com"; sshUser = "matthew"; buildOn = "remote"; # valid args are "local" or "remote" + substituteOnTarget = true; # if buildOn is "local" then it will substitute on the target, "-s" hermetic = false; }; } @@ -105,6 +106,13 @@ Connection to itchy.scratchy.com closed. Whether to copy Nix to the remote for usage when building and activating, instead of using the Nix which is already installed on the remote. +- `substituteOnTarget` *`bool`* + + Whether to fetch closures and paths from the remote, even when building + locally. This makes sense in most cases, because the remote will have already + built a lot of the paths from the previous deployment. However, if the remote + has a slow upload bandwidth, this would not be a good idea to enable. + # Project Principles * No Premature Optimization: Make it work, then optimize it later if the diff --git a/flake.nix b/flake.nix index c061db3..fb448c6 100644 --- a/flake.nix +++ b/flake.nix @@ -27,7 +27,7 @@ validMachines = final.lib.remove "" (final.lib.forEach machines (x: final.lib.optionalString (flake.nixosConfigurations."${x}"._module.args ? nixinate) "${x}" )); mkDeployScript = { machine, dryRun }: let inherit (builtins) abort; - inherit (final.lib) getExe; + inherit (final.lib) getExe optionalString; nix = "${getExe final.nix}"; nixos-rebuild = "${getExe final.nixos-rebuild}"; openssh = "${getExe final.openssh}"; @@ -38,6 +38,7 @@ 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"; script = '' @@ -58,7 +59,7 @@ '') else '' echo "🔨 Building system closure locally, copying it to remote store and activating it:" - ( set -x; NIX_SSHOPTS="-t" ${nixos-rebuild} ${switch} --flake ${flake}#${machine} --target-host ${user}@${host} --use-remote-sudo ) + ( set -x; NIX_SSHOPTS="-t" ${nixos-rebuild} ${switch} --flake ${flake}#${machine} --target-host ${user}@${host} --use-remote-sudo ${optionalString substituteOnTarget "-s"} ) ''); in final.writeScript "deploy-${machine}.sh" script; in -- 2.45.3