From f7afb02ad2bd56d50cd5be0565c3d8c45ae287a2 Mon Sep 17 00:00:00 2001 From: Charlotte Van Petegem Date: Wed, 18 Jan 2023 18:21:49 +0100 Subject: [PATCH] Fix local building for remote hosts --- patches/210382.patch | 96 +++++++++++++++++++++++++++++++++++++++++ shells/nixos-config.nix | 2 + 2 files changed, 98 insertions(+) create mode 100644 patches/210382.patch diff --git a/patches/210382.patch b/patches/210382.patch new file mode 100644 index 00000000..a48f2728 --- /dev/null +++ b/patches/210382.patch @@ -0,0 +1,96 @@ +From cc4de1aa3ad39c480e111113aec48da2e7c24e8d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Fabian=20M=C3=B6ller?= +Date: Fri, 13 Jan 2023 10:16:46 +0100 +Subject: [PATCH] nixos-rebuild: Allow local builds when --target-host is used + again + +This is a followup of #148921, to allow local builds when +`--target-host` is used again. It also documents the change in +behavior, regarding the specialty of the `localhost` value. + +By removing the special handling of an empty `buildHost` and non empty +`targetHost`, this change also slightly alters the behavior of +`nixos-rebuild`. + +Originally by specifying `--target-host target --build-host ""`, the +now removed special case would transform those arguments to +`--target-host target --build-host target`. +Now the empty `--build-host` would result in a local build. +--- + .../doc/manual/from_md/release-notes/rl-2305.section.xml | 9 +++++++++ + nixos/doc/manual/man-nixos-rebuild.xml | 6 +++--- + nixos/doc/manual/release-notes/rl-2305.section.md | 2 ++ + pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh | 4 ---- + 4 files changed, 14 insertions(+), 7 deletions(-) + +diff --git a/nixos/doc/manual/from_md/release-notes/rl-2305.section.xml b/nixos/doc/manual/from_md/release-notes/rl-2305.section.xml +index 242841a56b65b..7a8c7b10596a8 100644 +--- a/nixos/doc/manual/from_md/release-notes/rl-2305.section.xml ++++ b/nixos/doc/manual/from_md/release-notes/rl-2305.section.xml +@@ -256,6 +256,15 @@ + been changed to null. + + ++ ++ ++ The --target-host and ++ --build-host options of ++ nixos-rebuild no longer treat the ++ localhost value specially – to build ++ on/deploy to local machine, omit the relevant flag. ++ ++ + + + The nix.readOnlyStore option has been +diff --git a/nixos/doc/manual/man-nixos-rebuild.xml b/nixos/doc/manual/man-nixos-rebuild.xml +index cab871661a755..1b55d07c95022 100644 +--- a/nixos/doc/manual/man-nixos-rebuild.xml ++++ b/nixos/doc/manual/man-nixos-rebuild.xml +@@ -532,15 +532,15 @@ + + + Specifies the NixOS target host. By setting this to something other than +- localhost, the system activation will happen ++ an empty string, the system activation will happen + on the remote host instead of the local machine. The remote host needs to + be accessible over ssh, and for the commands , + and you need root access. + + + +- If is not explicitly specified, building +- will take place locally. ++ If is not explicitly specified or empty, ++ building will take place locally. + + + +diff --git a/nixos/doc/manual/release-notes/rl-2305.section.md b/nixos/doc/manual/release-notes/rl-2305.section.md +index b5c74836ef407..f6c71cc3da0ad 100644 +--- a/nixos/doc/manual/release-notes/rl-2305.section.md ++++ b/nixos/doc/manual/release-notes/rl-2305.section.md +@@ -67,6 +67,8 @@ In addition to numerous new and upgraded packages, this release has the followin + + - In `mastodon` it is now necessary to specify location of file with `PostgreSQL` database password. In `services.mastodon.database.passwordFile` parameter default value `/var/lib/mastodon/secrets/db-password` has been changed to `null`. + ++- The `--target-host` and `--build-host` options of `nixos-rebuild` no longer treat the `localhost` value specially – to build on/deploy to local machine, omit the relevant flag. ++ + - The `nix.readOnlyStore` option has been renamed to `boot.readOnlyNixStore` to clarify that it configures the NixOS boot process, not the Nix daemon. + + ## Other Notable Changes {#sec-release-23.05-notable-changes} +diff --git a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh +index 217e04d35720e..ed7c9231905a3 100755 +--- a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh ++++ b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh +@@ -148,10 +148,6 @@ if [[ -n "$SUDO_USER" || -n $remoteSudo ]]; then + maybeSudo=(sudo --preserve-env="$preservedSudoVars" --) + fi + +-if [[ -z "$buildHost" && -n "$targetHost" ]]; then +- buildHost="$targetHost" +-fi +- + # log the given argument to stderr if verbose mode is on + logVerbose() { + if [ -n "$verboseScript" ]; then diff --git a/shells/nixos-config.nix b/shells/nixos-config.nix index b4ea69ec..168ae090 100644 --- a/shells/nixos-config.nix +++ b/shells/nixos-config.nix @@ -1,6 +1,8 @@ { pkgs, inputs }: pkgs.devshell.mkShell { name = "NixOS config"; packages = [ + # Use nixos-rebuild from flake, since it might be patched + pkgs.nixos-rebuild pkgs.nixpkgs-fmt (pkgs.writeShellScriptBin "fetchpatch" "curl -L https://github.com/NixOS/nixpkgs/pull/$1.patch -o patches/$1.patch") inputs.agenix.defaultPackage.x86_64-linux