fix(nixos): add Core to git safe.directory and update nix-switch to path flake scheme
- Update nixos/configuration.nix to include /home/${operatorUser}/Core in programs.git.config.safe.directory, preventing dubious ownership errors when homelab-appctl runs read-only status checks
- Update nix-switch alias in nixos/modules/shell.nix to use path:$HOME/Core#server --impure, ensuring gitignored instance.nix domain injection evaluates reliably
- Add security invariant tests asserting safe.directory configuration and nix-switch alias format
This commit is contained in:
1 parent
caa8140cd3
commit
e2dbc97b0e
3 files changed
+55
-2
No files matched your search
@@ -22,6 +22,7 @@
|
|||||||
programs.git = {
|
programs.git = {
|
||||||
enable = true;
|
enable = true;
|
||||||
config.safe.directory = [
|
config.safe.directory = [
|
||||||
|
"/home/${config.homelab.operatorUser}/Core"
|
||||||
"/home/${config.homelab.operatorUser}/Sites/*"
|
"/home/${config.homelab.operatorUser}/Sites/*"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -62,8 +62,8 @@
|
|||||||
reload = "exec bash";
|
reload = "exec bash";
|
||||||
pgoog = "ping google.com -c 3";
|
pgoog = "ping google.com -c 3";
|
||||||
wifi = "nmtui";
|
wifi = "nmtui";
|
||||||
# NixOS rebuild targeting this flake
|
# NixOS rebuild targeting this flake (path scheme + impure required for instance.nix)
|
||||||
nix-switch = "sudo nixos-rebuild switch --flake ~/Core#server";
|
nix-switch = "sudo nixos-rebuild switch --flake path:$HOME/Core#server --impure";
|
||||||
};
|
};
|
||||||
|
|
||||||
interactiveShellInit = ''
|
interactiveShellInit = ''
|
||||||
|
|||||||
@@ -419,3 +419,55 @@ def test_gitignore_includes_instance_nix():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_nixos_switch_alias_uses_path_and_impure():
|
||||||
|
"""Ensure nix-switch alias in nixos/modules/shell.nix uses path: and --impure to prevent silent fail-open."""
|
||||||
|
shell_nix = CORE_ROOT / "nixos" / "modules" / "shell.nix"
|
||||||
|
content = shell_nix.read_text(encoding="utf-8")
|
||||||
|
assert 'nix-switch = "sudo nixos-rebuild switch --flake path:$HOME/Core#server --impure";' in content, (
|
||||||
|
"nixos/modules/shell.nix must configure nix-switch alias with path:$HOME/Core#server --impure"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_nixos_safe_directory_includes_core_and_sites():
|
||||||
|
"""Ensure programs.git.config.safe.directory includes Core and Sites to prevent dubious ownership errors."""
|
||||||
|
config_nix = CORE_ROOT / "nixos" / "configuration.nix"
|
||||||
|
content = config_nix.read_text(encoding="utf-8")
|
||||||
|
assert '"/home/${config.homelab.operatorUser}/Core"' in content, (
|
||||||
|
"nixos/configuration.nix must include Core in git safe.directory"
|
||||||
|
)
|
||||||
|
assert '"/home/${config.homelab.operatorUser}/Sites/*"' in content, (
|
||||||
|
"nixos/configuration.nix must include Sites/* in git safe.directory"
|
||||||
|
)
|
||||||
|
|
||||||
|
nix_bin = shutil.which("nix")
|
||||||
|
if nix_bin and not os.environ.get("NIX_BUILD_TOP"):
|
||||||
|
cmd = [
|
||||||
|
nix_bin,
|
||||||
|
"eval",
|
||||||
|
".#nixosConfigurations.server.config.programs.git.config",
|
||||||
|
"--json",
|
||||||
|
]
|
||||||
|
res = subprocess.run(
|
||||||
|
cmd, cwd=CORE_ROOT, capture_output=True, text=True, check=True
|
||||||
|
)
|
||||||
|
import json
|
||||||
|
|
||||||
|
configs = json.loads(res.stdout)
|
||||||
|
safe_dirs = []
|
||||||
|
for cfg in configs:
|
||||||
|
if isinstance(cfg, dict) and "safe" in cfg and "directory" in cfg["safe"]:
|
||||||
|
dirs = cfg["safe"]["directory"]
|
||||||
|
if isinstance(dirs, list):
|
||||||
|
safe_dirs.extend(dirs)
|
||||||
|
else:
|
||||||
|
safe_dirs.append(dirs)
|
||||||
|
|
||||||
|
assert "/home/operator/Core" in safe_dirs, (
|
||||||
|
f"Expected '/home/operator/Core' in git safe.directory, got {safe_dirs}"
|
||||||
|
)
|
||||||
|
assert "/home/operator/Sites/*" in safe_dirs, (
|
||||||
|
f"Expected '/home/operator/Sites/*' in git safe.directory, got {safe_dirs}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in new issue
Block a user