From 6b172212b632093b7b04397f55a4365f3712ecca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Thu, 18 Dec 2025 16:42:05 +0100 Subject: [PATCH] disko-install: resolve symlinks in mount point path Nix refuses to operate when the store path or its parent directories contain symlinks. On some systems /mnt can be a symlink, causing disko-install to fail with: error: the path '"/mnt"' is a symlink; this is not allowed for the Nix store and its parent directories Use realpath to resolve symlinks before passing the mount point to nix-store and nixos-install commands. --- disko-install | 3 +++ lib/make-disk-image.nix | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/disko-install b/disko-install index 6dbbdb4..1148115 100755 --- a/disko-install +++ b/disko-install @@ -224,6 +224,9 @@ main() { maybeRun mkdir -p "${mountPoint}" maybeRun chmod 755 "${mountPoint}" # bcachefs wants 755 + # Resolve symlinks in mountPoint path to satisfy nix-store requirements + # (nix refuses symlinks in store path hierarchy) + mountPoint=$(realpath "${mountPoint}") # shellcheck disable=SC2064 if [[ -z ${dry_run-} ]]; then trap cleanupMountPoint EXIT diff --git a/lib/make-disk-image.nix b/lib/make-disk-image.nix index 08f6467..d14c655 100644 --- a/lib/make-disk-image.nix +++ b/lib/make-disk-image.nix @@ -140,8 +140,11 @@ let installer = lib.optionalString cfg.copyNixStore '' ${binfmtSetup} unset NIX_REMOTE + # Resolve symlinks in rootMountPoint to satisfy nix-store requirements + # (nix refuses symlinks in store path hierarchy) + rootMountPoint=$(realpath ${lib.escapeShellArg systemToInstall.config.disko.rootMountPoint}) # populate nix db, so nixos-install doesn't complain - export NIX_STATE_DIR=${systemToInstall.config.disko.rootMountPoint}/nix/var/nix + export NIX_STATE_DIR=$rootMountPoint/nix/var/nix nix-store --load-db < "${closureInfo}/registration" # We copy files with cp because `nix copy` has a large memory leak. @@ -151,7 +154,7 @@ let # showed -P 8 is optimal: higher values (-P 16) hurt performance on some # systems, while -P 4 is ~30% slower. Cap at 8 but use fewer workers if the # system has fewer cores. - mkdir -p ${systemToInstall.config.disko.rootMountPoint}/nix/store + mkdir -p "$rootMountPoint"/nix/store ${ if cfg.copyNixStoreThreads == "auto" then '' @@ -162,10 +165,10 @@ let P=${toString cfg.copyNixStoreThreads} '' } - xargs -P "$P" -I {} cp --recursive {} ${systemToInstall.config.disko.rootMountPoint}/nix/store < ${closureInfo}/store-paths + xargs -P "$P" -I {} cp --recursive {} "$rootMountPoint"/nix/store < ${closureInfo}/store-paths - ${systemToInstall.config.system.build.nixos-install}/bin/nixos-install --root ${systemToInstall.config.disko.rootMountPoint} --system ${systemToInstall.config.system.build.toplevel} --keep-going --no-channel-copy -v --no-root-password --option binary-caches "" - umount -Rv ${lib.escapeShellArg systemToInstall.config.disko.rootMountPoint} + ${systemToInstall.config.system.build.nixos-install}/bin/nixos-install --root "$rootMountPoint" --system ${systemToInstall.config.system.build.toplevel} --keep-going --no-channel-copy -v --no-root-password --option binary-caches "" + umount -Rv "$rootMountPoint" ''; QEMU_OPTS = lib.concatStringsSep " " (