From 1ddc5d2b1162b6b6815820243a15396a338b973c Mon Sep 17 00:00:00 2001 From: Astro Date: Wed, 8 Sep 2021 22:48:13 +0200 Subject: [PATCH] flake.nix: add -nixos-rebuild-local --- README.md | 7 +++++++ flake.nix | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 688e0f4b..2590466f 100644 --- a/README.md +++ b/README.md @@ -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 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 A shell script that copies the current working tree, and runs diff --git a/flake.nix b/flake.nix index 6d404b18..f1516dce 100644 --- a/flake.nix +++ b/flake.nix @@ -70,7 +70,7 @@ # remote machine and bulding and switching there. # Can be run with nix run c3d2#deploy-… { name - , host ? "${name}.hq.c3d2.de" + , host # remote builders to pass , builders ? null }: @@ -146,6 +146,17 @@ } // nixpkgs.lib.optionalAttrs (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) );