From 12e016d32db7b271c1985e8f3e29a441d3d99845 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 24 Jun 2025 15:49:24 +0100 Subject: [PATCH 1/2] nixos-rebuild-ng: add FLAKE_FLAGS to `nix copy` --- pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py | 1 + pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py | 2 ++ pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_nix.py | 2 ++ 3 files changed, 5 insertions(+) diff --git a/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py b/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py index acc9448fec00..0d8abca0f92d 100644 --- a/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py +++ b/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py @@ -210,6 +210,7 @@ def copy_closure( run_wrapper( [ "nix", + *FLAKE_FLAGS, "copy", *dict_to_flags(copy_flags), "--from", diff --git a/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py b/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py index 504d016bbfbb..e3678420bc14 100644 --- a/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py +++ b/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py @@ -688,6 +688,8 @@ def test_execute_nix_switch_build_target_host( call( [ "nix", + "--extra-experimental-features", + "nix-command flakes", "copy", "--from", "ssh://user@build-host", diff --git a/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_nix.py b/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_nix.py index 05cb69e69d8b..1bca16260012 100644 --- a/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_nix.py +++ b/pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_nix.py @@ -263,6 +263,8 @@ def test_copy_closure(monkeypatch: MonkeyPatch) -> None: mock_run.assert_called_with( [ "nix", + "--extra-experimental-features", + "nix-command flakes", "copy", "--copy-flag", "--from", From 88fcdf4ef80148190465ff78c262d6d651813bb8 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Tue, 24 Jun 2025 15:51:54 +0100 Subject: [PATCH 2/2] nixos-rebuild-ng: allow `withNix218` to be overriden `withNix218` controls if `nixos-rebuild-ng` is built with Nix 2.18+, so it can use some features depending on newer version of Nix, for example using `nix copy` instead of `nix-copy-closure` for more efficient copies when both `--build-host` and `--target-host`. This is computed by looking at the Nix derivation at compile time. It is unlikely but it could happen that some specific use case an user wants to use the Nix <2.18 path without actually using an older version of Nix. For those cases we are exposing the `withNix218` as a derivation parameter, so it can be overriden. --- pkgs/by-name/ni/nixos-rebuild-ng/package.nix | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkgs/by-name/ni/nixos-rebuild-ng/package.nix b/pkgs/by-name/ni/nixos-rebuild-ng/package.nix index e29b7d924149..020b9ae7694a 100644 --- a/pkgs/by-name/ni/nixos-rebuild-ng/package.nix +++ b/pkgs/by-name/ni/nixos-rebuild-ng/package.nix @@ -15,6 +15,13 @@ # Very long tmp dirs lead to "too long for Unix domain socket" # SSH ControlPath errors. Especially macOS sets long TMPDIR paths. withTmpdir ? if stdenv.hostPlatform.isDarwin then "/tmp" else null, + # This version is kind of arbitrary, we use some features that were + # implemented in newer versions of Nix, but not necessary 2.18. + # However, Lix is a fork of Nix 2.18, so this looks like a good version + # to cut specific functionality. + # ATTN: This currently doesn't disambiguate between Nix and Lix, so using this + # in a conditional needs careful checking against both Nix implementations. + withNix218 ? lib.versionAtLeast nix.version "2.18", # passthru.tests nixosTests, nixVersions, @@ -23,13 +30,6 @@ }: let executable = if withNgSuffix then "nixos-rebuild-ng" else "nixos-rebuild"; - # This version is kind of arbitrary, we use some features that were - # implemented in newer versions of Nix, but not necessary 2.18. - # However, Lix is a fork of Nix 2.18, so this looks like a good version - # to cut specific functionality. - # ATTN: This currently doesn't disambiguate between Nix and Lix, so using this - # in a conditional needs careful checking against both Nix implementations. - withNix218 = lib.versionAtLeast nix.version "2.18"; in python3Packages.buildPythonApplication rec { pname = "nixos-rebuild-ng";