Add option to substitute on the target machine if local build #22

Merged
MagicRB merged 1 commit from master into master 2022-06-10 14:40:30 +00:00
2 changed files with 11 additions and 2 deletions
Showing only changes of commit b5683029f9 - Show all commits

View file

@ -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

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}" ));
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