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 84382292ce7c..218eaa8d395f 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") 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",