From 2e1d60e197e2c5f5724424e2a24b58cca2631953 Mon Sep 17 00:00:00 2001 From: azuwis Date: Mon, 1 Jun 2026 20:05:16 +0800 Subject: [PATCH 1/2] nixos-rebuild-ng: disable flake auto-detection when --file or --attr is used When --file or --attr is explicitly passed, flake auto-detection should not override the user's intent to use a non-flake configuration. --- pkgs/by-name/ni/nixos-rebuild-ng/nixos-rebuild.8.scd | 5 ++++- .../ni/nixos-rebuild-ng/src/nixos_rebuild/__init__.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkgs/by-name/ni/nixos-rebuild-ng/nixos-rebuild.8.scd b/pkgs/by-name/ni/nixos-rebuild-ng/nixos-rebuild.8.scd index 7ec6def5ca21..48a0fb8312d1 100644 --- a/pkgs/by-name/ni/nixos-rebuild-ng/nixos-rebuild.8.scd +++ b/pkgs/by-name/ni/nixos-rebuild-ng/nixos-rebuild.8.scd @@ -314,13 +314,16 @@ It must be one of the following: be made using _nixos_ function in nixpkgs or importing and calling nixos/lib/eval-config.nix from nixpkgs. If specified without *--attr* option, builds the configuration from the top-level attribute set of the - file. + file. Using this option disables automatic flake detection, same as + *--no-flake*. *--attr* _attrPath_, *-A* _attrPath_ Build the NixOS system from a nix file and use the specified attribute path from the file specified by the *--file* option. If specified without *--file* option, uses _system.nix_ in current directory, the system-wide __ file, or finally, /etc/nixos/system.nix. + Using this option disables automatic flake detection, same as + *--no-flake*. *--flake* _flake-uri[#name]_, *-F* _flake-uri[#name]_ Build the NixOS system from the specified flake. It defaults to the diff --git a/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/__init__.py b/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/__init__.py index c1ad2bde3d00..db0fe7a4ec5c 100644 --- a/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/__init__.py +++ b/pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/__init__.py @@ -329,6 +329,10 @@ def parse_args( if args.flake and (args.file or args.attr): parser.error("--flake cannot be used with --file or --attr") + if (args.file or args.attr) and args.flake is None: + # Disable flake auto-detection when --file or --attr is used + args.flake = False + if args.store_path: if args.rollback: parser.error("--store-path and --rollback are mutually exclusive") From b63a81166a10957b70d303c181adbec59c0f74f4 Mon Sep 17 00:00:00 2001 From: azuwis Date: Thu, 4 Jun 2026 20:01:07 +0800 Subject: [PATCH 2/2] nixos-rebuild-ng: add tests for --file/--attr disabling flake auto-detection --- .../ni/nixos-rebuild-ng/src/tests/test_main.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 1e0e5779ac90..12bacafba8d5 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 @@ -89,6 +89,22 @@ def test_parse_args() -> None: assert r_store_path.flake is False assert r_store_path.store_path == "/nix/store/foo" + # --file and --attr should disable flake auto-detection + r_file, _ = nr.parse_args(["nixos-rebuild", "switch", "--file", "foo.nix"]) + assert r_file.flake is False + assert r_file.file == "foo.nix" + + r_attr, _ = nr.parse_args(["nixos-rebuild", "switch", "--attr", "bar"]) + assert r_attr.flake is False + assert r_attr.attr == "bar" + + r_file_attr, _ = nr.parse_args( + ["nixos-rebuild", "switch", "--file", "foo.nix", "--attr", "bar"] + ) + assert r_file_attr.flake is False + assert r_file_attr.file == "foo.nix" + assert r_file_attr.attr == "bar" + r1, g1 = nr.parse_args( [ "nixos-rebuild",