flake.nix: add -nixos-rebuild-local

This commit is contained in:
Astro 2021-09-08 22:48:13 +02:00
parent 2c950f0a8d
commit 1ddc5d2b11
2 changed files with 19 additions and 1 deletions

View File

@ -66,6 +66,13 @@ for example: `nix run c3d2#glotzbert-nixos-rebuild switch`. Use `nix flake show
to show what is available. Note that the deploy scripts only work if to show what is available. Note that the deploy scripts only work if
the target machines already has flakes enabled. the target machines already has flakes enabled.
Now that there is a `-local` variant that builds the system profile on
your machine (possibly reusing dependencies that were built for other
hosts), flakification of an existing NixOS host can be done using `nix
run c3d2#glotzbert-nixos-rebuild-local switch`
The must be an existing `nixosConfiguration.${host}` in `flake.nix`.
### Remote deployment from non-NixOS ### Remote deployment from non-NixOS
A shell script that copies the current working tree, and runs A shell script that copies the current working tree, and runs

View File

@ -70,7 +70,7 @@
# remote machine and bulding and switching there. # remote machine and bulding and switching there.
# Can be run with nix run c3d2#deploy-… # Can be run with nix run c3d2#deploy-…
{ name { name
, host ? "${name}.hq.c3d2.de" , host
# remote builders to pass # remote builders to pass
, builders ? null , builders ? null
}: }:
@ -146,6 +146,17 @@
} // nixpkgs.lib.optionalAttrs (hostRegistry.hosts.${name} ? builders) { } // nixpkgs.lib.optionalAttrs (hostRegistry.hosts.${name} ? builders) {
inherit (hostRegistry.hosts.${name}) builders; inherit (hostRegistry.hosts.${name}) builders;
}); });
"${name}-nixos-rebuild-local" =
let
host = getHostAddr name;
target = ''root@"${host}"'';
profile = self.nixosConfigurations.${name}.config.system.build.toplevel;
in pkgs.writeScriptBin "${name}-nixos-rebuild" ''
#!${pkgs.runtimeShell} -e
nix-copy-closure --to ${target} ${profile}
exec ssh -t ${target} "${profile}/bin/switch-to-configuration $@"
'';
}) {} (builtins.attrNames flakifiedHosts) }) {} (builtins.attrNames flakifiedHosts)
); );