From a009d2b73f072a09781e2b0397628ecb9df142a9 Mon Sep 17 00:00:00 2001 From: taku0 Date: Sun, 3 Nov 2024 20:40:21 +0900 Subject: [PATCH] nixos-container: do not touch os-release if it is a symlink `/etc/os-release` of NixOS containers, which are `/var/lib/nixos-containers/*/etc/os-release` on the host, are usually symlinks to the absolute path `/etc/static/os-release` but it doesn't exist in non-NixOS host. Since `startScript` is evaluated by the host system, both `[ -e "$root/etc/os-release" ]` and `touch "$root/etc/os-release"` fail, so that the container fails to start on the second boot (on the first boot, the symlink doesn't exist, so the command succeeds). This commit avoids `touch "$root/etc/os-release"` if `$root/etc/os-release` is a symlink, so imperative NixOS containers are usable on non-NixOS host. --- nixos/modules/virtualisation/nixos-containers.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/virtualisation/nixos-containers.nix b/nixos/modules/virtualisation/nixos-containers.nix index 812d22d773e1..a9632563beec 100644 --- a/nixos/modules/virtualisation/nixos-containers.nix +++ b/nixos/modules/virtualisation/nixos-containers.nix @@ -92,7 +92,7 @@ let chmod 0755 "$root/etc" "$root/var/lib" mkdir -p "$root/var/lib/private" "$root/root" /run/nixos-containers chmod 0700 "$root/var/lib/private" "$root/root" /run/nixos-containers - if ! [ -e "$root/etc/os-release" ]; then + if ! [ -e "$root/etc/os-release" ] && ! [ -h "$root/etc/os-release" ]; then touch "$root/etc/os-release" fi