nixos-rebuild-ng: quote hostname (#412341)

Changed files
+30 -26
pkgs
by-name
ni
nixos-rebuild-ng
+1 -1
pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/models.py
···
m = cls._re.match(flake_str)
assert m is not None, f"got no matches for {flake_str}"
attr = m.group("attr")
-
nixos_attr = f"nixosConfigurations.{attr or hostname_fn() or 'default'}"
+
nixos_attr = f'nixosConfigurations."{attr or hostname_fn() or "default"}"'
path_str = m.group("path")
if ":" in path_str:
return cls(path_str, nixos_attr)
+7 -7
pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py
···
"nix",
"eval",
"--json",
-
"/path/to/config#nixosConfigurations.hostname.config.system.build.images",
+
'/path/to/config#nixosConfigurations."hostname".config.system.build.images',
"--apply",
"builtins.attrNames",
],
···
"nix-command flakes",
"build",
"--print-out-paths",
-
"/path/to/config#nixosConfigurations.hostname.config.system.build.images.azure",
+
'/path/to/config#nixosConfigurations."hostname".config.system.build.images.azure',
],
check=True,
stdout=PIPE,
···
"nix",
"eval",
"--json",
-
"/path/to/config#nixosConfigurations.hostname.config.system.build.images.azure.passthru.filePath",
+
'/path/to/config#nixosConfigurations."hostname".config.system.build.images.azure.passthru.filePath',
],
check=True,
stdout=PIPE,
···
"nix-command flakes",
"build",
"--print-out-paths",
-
"/path/to/config#nixosConfigurations.hostname.config.system.build.toplevel",
+
'/path/to/config#nixosConfigurations."hostname".config.system.build.toplevel',
"-v",
"--option",
"narinfo-cache-negative-ttl",
···
"nix-command flakes",
"build",
"--print-out-paths",
-
"/path/to/config#nixosConfigurations.hostname.config.system.build.toplevel",
+
'/path/to/config#nixosConfigurations."hostname".config.system.build.toplevel',
"--no-link",
],
check=True,
···
"nix-command flakes",
"eval",
"--raw",
-
"/path/to/config#nixosConfigurations.hostname.config.system.build.toplevel.drvPath",
+
'/path/to/config#nixosConfigurations."hostname".config.system.build.toplevel.drvPath',
],
check=True,
stdout=PIPE,
···
"nix-command flakes",
"build",
"--print-out-paths",
-
"github:user/repo#nixosConfigurations.hostname.config.system.build.toplevel",
+
'github:user/repo#nixosConfigurations."hostname".config.system.build.toplevel',
],
check=True,
stdout=PIPE,
+19 -15
pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_models.py
···
def test_flake_parse(tmpdir: Path, monkeypatch: MonkeyPatch) -> None:
assert m.Flake.parse("/path/to/flake#attr") == m.Flake(
-
Path("/path/to/flake"), "nixosConfigurations.attr"
+
Path("/path/to/flake"), 'nixosConfigurations."attr"'
)
assert m.Flake.parse("/path/ to /flake", lambda: "hostname") == m.Flake(
-
Path("/path/ to /flake"), "nixosConfigurations.hostname"
+
Path("/path/ to /flake"), 'nixosConfigurations."hostname"'
)
assert m.Flake.parse("/path/to/flake", lambda: "hostname") == m.Flake(
-
Path("/path/to/flake"), "nixosConfigurations.hostname"
+
Path("/path/to/flake"), 'nixosConfigurations."hostname"'
)
# change directory to tmpdir
with monkeypatch.context() as patch_context:
patch_context.chdir(tmpdir)
-
assert m.Flake.parse(".#attr") == m.Flake(Path("."), "nixosConfigurations.attr")
-
assert m.Flake.parse("#attr") == m.Flake(Path("."), "nixosConfigurations.attr")
-
assert m.Flake.parse(".") == m.Flake(Path("."), "nixosConfigurations.default")
+
assert m.Flake.parse(".#attr") == m.Flake(
+
Path("."), 'nixosConfigurations."attr"'
+
)
+
assert m.Flake.parse("#attr") == m.Flake(
+
Path("."), 'nixosConfigurations."attr"'
+
)
+
assert m.Flake.parse(".") == m.Flake(Path("."), 'nixosConfigurations."default"')
assert m.Flake.parse("path:/to/flake#attr") == m.Flake(
-
"path:/to/flake", "nixosConfigurations.attr"
+
"path:/to/flake", 'nixosConfigurations."attr"'
)
assert m.Flake.parse("github:user/repo/branch") == m.Flake(
-
"github:user/repo/branch", "nixosConfigurations.default"
+
"github:user/repo/branch", 'nixosConfigurations."default"'
)
git_root = tmpdir / "git_root"
git_root.mkdir()
(git_root / ".git").mkdir()
assert m.Flake.parse(str(git_root)) == m.Flake(
-
f"git+file://{git_root}", "nixosConfigurations.default"
+
f"git+file://{git_root}", 'nixosConfigurations."default"'
)
work_tree = tmpdir / "work_tree"
work_tree.mkdir()
(work_tree / ".git").write_text("gitdir: /path/to/git", "utf-8")
assert m.Flake.parse(str(work_tree)) == m.Flake(
-
"git+file:///path/to/git", "nixosConfigurations.default"
+
"git+file:///path/to/git", 'nixosConfigurations."default"'
)
···
# Flake string
assert m.Flake.from_arg("/path/to/flake#attr", None) == m.Flake(
-
Path("/path/to/flake"), "nixosConfigurations.attr"
+
Path("/path/to/flake"), 'nixosConfigurations."attr"'
)
# False
···
with monkeypatch.context() as patch_context:
patch_context.chdir(tmpdir)
assert m.Flake.from_arg(True, None) == m.Flake(
-
Path("."), "nixosConfigurations.hostname"
+
Path("."), 'nixosConfigurations."hostname"'
)
# None when we do not have /etc/nixos/flake.nix
···
),
):
assert m.Flake.from_arg(None, None) == m.Flake(
-
"git+file:///etc/nixos", "nixosConfigurations.hostname"
+
"git+file:///etc/nixos", 'nixosConfigurations."hostname"'
)
with (
···
),
):
assert m.Flake.from_arg(None, None) == m.Flake(
-
Path("/path/to"), "nixosConfigurations.hostname"
+
Path("/path/to"), 'nixosConfigurations."hostname"'
)
with (
···
),
):
assert m.Flake.from_arg("/path/to", m.Remote("user@host", [], None)) == m.Flake(
-
Path("/path/to"), "nixosConfigurations.remote-hostname"
+
Path("/path/to"), 'nixosConfigurations."remote-hostname"'
)
+3 -3
pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_nix.py
···
"nix-command flakes",
"build",
"--print-out-paths",
-
".#nixosConfigurations.hostname.config.system.build.toplevel",
+
'.#nixosConfigurations."hostname".config.system.build.toplevel',
"--no-link",
"--nix-flag",
"foo",
···
"nix-command flakes",
"eval",
"--raw",
-
".#nixosConfigurations.hostname.config.system.build.toplevel.drvPath",
+
'.#nixosConfigurations."hostname".config.system.build.toplevel.drvPath',
"--flake",
],
stdout=PIPE,
···
"edit",
"--commit-lock-file",
"--",
-
f"{tmpdir}#nixosConfigurations.attr",
+
f'{tmpdir}#nixosConfigurations."attr"',
],
check=False,
)