Skip to content

Commit 583b497

Browse files
committed
nixos-rebuild-ng: quote hostname
Fix #412328.
1 parent 1c7b92b commit 583b497

File tree

4 files changed

+30
-26
lines changed

4 files changed

+30
-26
lines changed

pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def parse(
122122
m = cls._re.match(flake_str)
123123
assert m is not None, f"got no matches for {flake_str}"
124124
attr = m.group("attr")
125-
nixos_attr = f"nixosConfigurations.{attr or hostname_fn() or 'default'}"
125+
nixos_attr = f'nixosConfigurations."{attr or hostname_fn() or "default"}"'
126126
path_str = m.group("path")
127127
if ":" in path_str:
128128
return cls(path_str, nixos_attr)

pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_main.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def run_side_effect(args: list[str], **kwargs: Any) -> CompletedProcess[str]:
385385
"nix",
386386
"eval",
387387
"--json",
388-
"/path/to/config#nixosConfigurations.hostname.config.system.build.images",
388+
'/path/to/config#nixosConfigurations."hostname".config.system.build.images',
389389
"--apply",
390390
"builtins.attrNames",
391391
],
@@ -400,7 +400,7 @@ def run_side_effect(args: list[str], **kwargs: Any) -> CompletedProcess[str]:
400400
"nix-command flakes",
401401
"build",
402402
"--print-out-paths",
403-
"/path/to/config#nixosConfigurations.hostname.config.system.build.images.azure",
403+
'/path/to/config#nixosConfigurations."hostname".config.system.build.images.azure',
404404
],
405405
check=True,
406406
stdout=PIPE,
@@ -411,7 +411,7 @@ def run_side_effect(args: list[str], **kwargs: Any) -> CompletedProcess[str]:
411411
"nix",
412412
"eval",
413413
"--json",
414-
"/path/to/config#nixosConfigurations.hostname.config.system.build.images.azure.passthru.filePath",
414+
'/path/to/config#nixosConfigurations."hostname".config.system.build.images.azure.passthru.filePath',
415415
],
416416
check=True,
417417
stdout=PIPE,
@@ -462,7 +462,7 @@ def run_side_effect(args: list[str], **kwargs: Any) -> CompletedProcess[str]:
462462
"nix-command flakes",
463463
"build",
464464
"--print-out-paths",
465-
"/path/to/config#nixosConfigurations.hostname.config.system.build.toplevel",
465+
'/path/to/config#nixosConfigurations."hostname".config.system.build.toplevel',
466466
"-v",
467467
"--option",
468468
"narinfo-cache-negative-ttl",
@@ -756,7 +756,7 @@ def run_side_effect(args: list[str], **kwargs: Any) -> CompletedProcess[str]:
756756
"nix-command flakes",
757757
"build",
758758
"--print-out-paths",
759-
"/path/to/config#nixosConfigurations.hostname.config.system.build.toplevel",
759+
'/path/to/config#nixosConfigurations."hostname".config.system.build.toplevel',
760760
"--no-link",
761761
],
762762
check=True,
@@ -860,7 +860,7 @@ def run_side_effect(args: list[str], **kwargs: Any) -> CompletedProcess[str]:
860860
"nix-command flakes",
861861
"eval",
862862
"--raw",
863-
"/path/to/config#nixosConfigurations.hostname.config.system.build.toplevel.drvPath",
863+
'/path/to/config#nixosConfigurations."hostname".config.system.build.toplevel.drvPath',
864864
],
865865
check=True,
866866
stdout=PIPE,
@@ -1063,7 +1063,7 @@ def run_side_effect(args: list[str], **kwargs: Any) -> CompletedProcess[str]:
10631063
"nix-command flakes",
10641064
"build",
10651065
"--print-out-paths",
1066-
"github:user/repo#nixosConfigurations.hostname.config.system.build.toplevel",
1066+
'github:user/repo#nixosConfigurations."hostname".config.system.build.toplevel',
10671067
],
10681068
check=True,
10691069
stdout=PIPE,

pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_models.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,42 @@ def test_build_attr_to_attr() -> None:
3232

3333
def test_flake_parse(tmpdir: Path, monkeypatch: MonkeyPatch) -> None:
3434
assert m.Flake.parse("/path/to/flake#attr") == m.Flake(
35-
Path("/path/to/flake"), "nixosConfigurations.attr"
35+
Path("/path/to/flake"), 'nixosConfigurations."attr"'
3636
)
3737
assert m.Flake.parse("/path/ to /flake", lambda: "hostname") == m.Flake(
38-
Path("/path/ to /flake"), "nixosConfigurations.hostname"
38+
Path("/path/ to /flake"), 'nixosConfigurations."hostname"'
3939
)
4040
assert m.Flake.parse("/path/to/flake", lambda: "hostname") == m.Flake(
41-
Path("/path/to/flake"), "nixosConfigurations.hostname"
41+
Path("/path/to/flake"), 'nixosConfigurations."hostname"'
4242
)
4343
# change directory to tmpdir
4444
with monkeypatch.context() as patch_context:
4545
patch_context.chdir(tmpdir)
46-
assert m.Flake.parse(".#attr") == m.Flake(Path("."), "nixosConfigurations.attr")
47-
assert m.Flake.parse("#attr") == m.Flake(Path("."), "nixosConfigurations.attr")
48-
assert m.Flake.parse(".") == m.Flake(Path("."), "nixosConfigurations.default")
46+
assert m.Flake.parse(".#attr") == m.Flake(
47+
Path("."), 'nixosConfigurations."attr"'
48+
)
49+
assert m.Flake.parse("#attr") == m.Flake(
50+
Path("."), 'nixosConfigurations."attr"'
51+
)
52+
assert m.Flake.parse(".") == m.Flake(Path("."), 'nixosConfigurations."default"')
4953
assert m.Flake.parse("path:/to/flake#attr") == m.Flake(
50-
"path:/to/flake", "nixosConfigurations.attr"
54+
"path:/to/flake", 'nixosConfigurations."attr"'
5155
)
5256
assert m.Flake.parse("github:user/repo/branch") == m.Flake(
53-
"github:user/repo/branch", "nixosConfigurations.default"
57+
"github:user/repo/branch", 'nixosConfigurations."default"'
5458
)
5559
git_root = tmpdir / "git_root"
5660
git_root.mkdir()
5761
(git_root / ".git").mkdir()
5862
assert m.Flake.parse(str(git_root)) == m.Flake(
59-
f"git+file://{git_root}", "nixosConfigurations.default"
63+
f"git+file://{git_root}", 'nixosConfigurations."default"'
6064
)
6165

6266
work_tree = tmpdir / "work_tree"
6367
work_tree.mkdir()
6468
(work_tree / ".git").write_text("gitdir: /path/to/git", "utf-8")
6569
assert m.Flake.parse(str(work_tree)) == m.Flake(
66-
"git+file:///path/to/git", "nixosConfigurations.default"
70+
"git+file:///path/to/git", 'nixosConfigurations."default"'
6771
)
6872

6973

@@ -84,7 +88,7 @@ def test_flake_from_arg(
8488

8589
# Flake string
8690
assert m.Flake.from_arg("/path/to/flake#attr", None) == m.Flake(
87-
Path("/path/to/flake"), "nixosConfigurations.attr"
91+
Path("/path/to/flake"), 'nixosConfigurations."attr"'
8892
)
8993

9094
# False
@@ -94,7 +98,7 @@ def test_flake_from_arg(
9498
with monkeypatch.context() as patch_context:
9599
patch_context.chdir(tmpdir)
96100
assert m.Flake.from_arg(True, None) == m.Flake(
97-
Path("."), "nixosConfigurations.hostname"
101+
Path("."), 'nixosConfigurations."hostname"'
98102
)
99103

100104
# None when we do not have /etc/nixos/flake.nix
@@ -124,7 +128,7 @@ def test_flake_from_arg(
124128
),
125129
):
126130
assert m.Flake.from_arg(None, None) == m.Flake(
127-
"git+file:///etc/nixos", "nixosConfigurations.hostname"
131+
"git+file:///etc/nixos", 'nixosConfigurations."hostname"'
128132
)
129133

130134
with (
@@ -145,7 +149,7 @@ def test_flake_from_arg(
145149
),
146150
):
147151
assert m.Flake.from_arg(None, None) == m.Flake(
148-
Path("/path/to"), "nixosConfigurations.hostname"
152+
Path("/path/to"), 'nixosConfigurations."hostname"'
149153
)
150154

151155
with (
@@ -156,7 +160,7 @@ def test_flake_from_arg(
156160
),
157161
):
158162
assert m.Flake.from_arg("/path/to", m.Remote("user@host", [], None)) == m.Flake(
159-
Path("/path/to"), "nixosConfigurations.remote-hostname"
163+
Path("/path/to"), 'nixosConfigurations."remote-hostname"'
160164
)
161165

162166

pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_nix.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_build_flake(mock_run: Mock, monkeypatch: MonkeyPatch, tmpdir: Path) ->
6868
"nix-command flakes",
6969
"build",
7070
"--print-out-paths",
71-
".#nixosConfigurations.hostname.config.system.build.toplevel",
71+
'.#nixosConfigurations."hostname".config.system.build.toplevel',
7272
"--no-link",
7373
"--nix-flag",
7474
"foo",
@@ -194,7 +194,7 @@ def test_build_remote_flake(
194194
"nix-command flakes",
195195
"eval",
196196
"--raw",
197-
".#nixosConfigurations.hostname.config.system.build.toplevel.drvPath",
197+
'.#nixosConfigurations."hostname".config.system.build.toplevel.drvPath',
198198
"--flake",
199199
],
200200
stdout=PIPE,
@@ -304,7 +304,7 @@ def test_edit(mock_run: Mock, monkeypatch: MonkeyPatch, tmpdir: Path) -> None:
304304
"edit",
305305
"--commit-lock-file",
306306
"--",
307-
f"{tmpdir}#nixosConfigurations.attr",
307+
f'{tmpdir}#nixosConfigurations."attr"',
308308
],
309309
check=False,
310310
)

0 commit comments

Comments
 (0)