mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-06-05 21:03:40 +00:00
nixos-rebuild-ng: disable flake auto-detection when --file or --attr is used (#527046)
This commit is contained in:
@@ -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 _<nixos-system>_ 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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user