diff options
author | Soispha <soispha@vhack.eu> | 2023-07-05 21:09:19 +0200 |
---|---|---|
committer | Soispha <soispha@vhack.eu> | 2023-07-05 21:09:19 +0200 |
commit | 393f0e672e16fe9b8c28e3a1e68478cdc186d480 (patch) | |
tree | 789edfefa3c7a6bed2af925a681416655d836d0b /system/services/nix-sync | |
parent | Fix(system/services/nix-sync): Really remove last reference to git-sync (diff) | |
download | nixos-server-393f0e672e16fe9b8c28e3a1e68478cdc186d480.tar.gz nixos-server-393f0e672e16fe9b8c28e3a1e68478cdc186d480.zip |
Fix(system/services/nix-sync): Rebuild website on gc
Diffstat (limited to '')
-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}"; |