From 2adfa79ef821cf18f3fb3dbf8f8476c9a1eea539 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sun, 2 Jun 2024 21:46:10 +0200 Subject: fix(nix-sync): Ensure that the `target` for `ln` never ends with a `/` Otherwise, `ln` tries to create the symlink _in_ the target directory. --- system/services/nix-sync/default.nix | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/services/nix-sync/default.nix b/system/services/nix-sync/default.nix index b4a9803..8de5e3c 100644 --- a/system/services/nix-sync/default.nix +++ b/system/services/nix-sync/default.nix @@ -34,6 +34,12 @@ if lib.strings.hasPrefix "/" repo.path then "" else "/"; + /* + * `ln` tries to create a symlink in the directory, if the target ends with a '/', + * thus remove it. + */ + repoPath = lib.strings.removeSuffix "/" repo.path; + repoCachePath = cfg.cachePath + optionalPathSeparator + repo.path; execStartScript = pkgs.writeScript "nix-sync-exec" '' #! /usr/bin/env dash @@ -52,7 +58,7 @@ [ "$(wc -l < "$out_paths")" -gt 1 ] && (echo "To many out-paths"; exit 1) out_path="$(cat "$out_paths")"; rm ${esa repo.path}; - ln -s "$out_path" ${esa repo.path}; + ln -s "$out_path" ${esa repoPath}; rm "$out_paths"; fi ''; @@ -67,7 +73,7 @@ nix build ${esa repoCachePath} --print-out-paths --experimental-features 'nix-command flakes' > "$out_paths"; [ "$(wc -l < "$out_paths")" -gt 1 ] && (echo "To many out-paths"; exit 1) out_path="$(cat "$out_paths")"; - ln -s "$out_path" ${esa repo.path}; + ln -s "$out_path" ${esa repoPath}; rm "$out_paths"; fi @@ -88,7 +94,7 @@ fi [ -e ${esa repo.path} ] && rm ${esa repo.path}; - ln -s "$out_path" ${esa repo.path}; + ln -s "$out_path" ${esa repoPath}; rm "$out_paths"; fi ''; -- cgit 1.4.1