Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/etc: support direct symlinks with etc overlay #314579

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions nixos/modules/system/etc/build-composefs-dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def main() -> None:
paths[glob_target] = composefs_path
add_leading_directories(glob_target, attrs, paths)
else: # Without globbing
if mode == "symlink":
if mode == "symlink" or mode == "direct-symlink":
composefs_path = ComposefsPath(
attrs,
# A high approximation of the size of a symlink
Expand All @@ -184,24 +184,23 @@ def main() -> None:
mode="0777",
payload=source,
)
elif os.path.isdir(source):
composefs_path = ComposefsPath(
attrs,
size=4096,
filetype=FileType.directory,
mode=mode,
payload=source,
)
else:
if os.path.isdir(source):
composefs_path = ComposefsPath(
attrs,
size=4096,
filetype=FileType.directory,
mode=mode,
payload=source,
)
else:
composefs_path = ComposefsPath(
attrs,
size=os.stat(source).st_size,
filetype=FileType.file,
mode=mode,
# payload needs to be relative path in this case
payload=target.lstrip("/"),
)
composefs_path = ComposefsPath(
attrs,
size=os.stat(source).st_size,
filetype=FileType.file,
mode=mode,
# payload needs to be relative path in this case
payload=target.lstrip("/"),
)
paths[target] = composefs_path
add_leading_directories(target, attrs, paths)

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/system/etc/etc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ let
]) etc'}
'';

etcHardlinks = filter (f: f.mode != "symlink") etc';
etcHardlinks = filter (f: f.mode != "symlink" && f.mode != "direct-symlink") etc';

build-composefs-dump = pkgs.runCommand "build-composefs-dump.py"
{
Expand Down
4 changes: 4 additions & 0 deletions nixos/tests/activation/etc-overlay-immutable.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
users.mutableUsers = false;
boot.initrd.systemd.enable = true;
boot.kernelPackages = pkgs.linuxPackages_latest;
time.timeZone = "Utc";

specialisation.new-generation.configuration = {
environment.etc."newgen".text = "newgen";
Expand All @@ -23,6 +24,9 @@
with subtest("/etc is mounted as an overlay"):
machine.succeed("findmnt --kernel --type overlay /etc")

with subtest("direct symlinks point to the target without indirection"):
assert machine.succeed("readlink -n /etc/localtime") == "/etc/zoneinfo/Utc"

with subtest("switching to the same generation"):
machine.succeed("/run/current-system/bin/switch-to-configuration test")

Expand Down