diff options
Diffstat (limited to 'system/services/nix-sync/default.nix')
-rw-r--r-- | system/services/nix-sync/default.nix | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/system/services/nix-sync/default.nix b/system/services/nix-sync/default.nix index 4440d59..8652b43 100644 --- a/system/services/nix-sync/default.nix +++ b/system/services/nix-sync/default.nix @@ -15,13 +15,13 @@ after = ["network-online.target"]; }; + parents = path: let + split_path = builtins.split "/" path; + filename = builtins.elemAt split_path (builtins.length split_path - 1); + in + lib.strings.removeSuffix "/" (builtins.replaceStrings [filename] [""] path); + esa = lib.strings.escapeShellArg; mkUnit = name: repo: let - esa = lib.strings.escapeShellArg; - parents = path: let - split_path = builtins.split "/" path; - filename = builtins.elemAt split_path (builtins.length split_path - 1); - in - lib.strings.removeSuffix "/" (builtins.replaceStrings [filename] [""] path); optionalPathSeparator = if lib.strings.hasPrefix "/" repo.path then "" @@ -36,7 +36,6 @@ origin="$(git rev-parse @{u})"; branch="$(git rev-parse @)"; - # FIXME: this will fail, after a `nix store gc` as the link is not in the gc-roots if ! [ "$origin" = "$branch" ]; then git pull; @@ -44,14 +43,15 @@ nix build . --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")"; - rm -r ${esa repo.path}; + rm ${esa repo.path}; ln -s "$out_path" ${esa repo.path}; rm "$out_paths"; fi ''; execStartPreScript = '' export XDG_CACHE_HOME="$CACHE_DIRECTORY"; - if ! stat ${esa repoCachePath}/.git 1>/dev/null 2>&1; then + + if ! [ -d ${esa repoCachePath}/.git ]; then mkdir --parents ${esa repoCachePath}; git clone ${esa repo.uri} ${esa repoCachePath}; @@ -62,6 +62,18 @@ ln -s "$out_path" ${esa repo.path}; rm "$out_paths"; fi + + if ! [ -L ${esa repo.path} ]; then + cd ${esa repoCachePath}; + + out_paths=$(mktemp); + nix build . --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")"; + rm ${esa repo.path}; + ln -s "$out_path" ${esa repo.path}; + rm "$out_paths"; + fi ''; in { description = "Nix Sync ${name}"; |