From a8bfcdf17f991f5550e664f947e89b6cd5ec423d Mon Sep 17 00:00:00 2001 From: arcnmx Date: Wed, 19 May 2021 08:30:38 -0700 Subject: [PATCH] ensure sources are cached locally before building --- ci/hosts.nix | 10 ++++++++++ ci/niv-cron.nix | 11 ++++++++--- default.nix | 12 ++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/ci/hosts.nix b/ci/hosts.nix index e197458e..83569450 100644 --- a/ci/hosts.nix +++ b/ci/hosts.nix @@ -4,6 +4,16 @@ ci.gh-actions.export = true; channels.nixfiles.path = ../.; + # ensure sources are fetched and available in the local store before evaluating host configs + environment.bootstrap = { + sourceCache = channels.cipkgs.runCommand "sources" { + srcs = attrNames channels.nixfiles.sourceCache.local; + } '' + mkdir -p $out/share/sources + ln -s $srcs $out/share/sources/ + ''; + }; + jobs = let hostnames = [ "samhain" "yule" "athame" ]; in mapAttrs' (k: nameValuePair "host-${k}") (genAttrs hostnames (host: { tasks.${host}.inputs = channels.nixfiles.hosts.${host}.config.system.build.toplevel; diff --git a/ci/niv-cron.nix b/ci/niv-cron.nix index 611f0d0e..68991f0c 100644 --- a/ci/niv-cron.nix +++ b/ci/niv-cron.nix @@ -51,11 +51,14 @@ with lib; { done if git status --porcelain | grep -qF nix/sources.json; then + nix build --no-link -f . sourceCache.local if nix build -Lf . hosts.{athame,yule,samhain}.config.system.build.toplevel; then - nix build -f ../. sourceCache if [[ -n $CACHIX_SIGNING_KEY ]]; then - cachix push kittywitch $(nix eval '(toString (import ../.).sourceCache)') - nix-build $(echo "-A hosts."{athame,yule,samhain}.config.system.build.toplevel) | cachix push kittywitch + nix build --no-link -f . sourceCache.all + cachix push kittywitch $(nix eval -f . sourceCache.allStr) + + cachix push kittywitch result*/ & + CACHIX_PUSH=$! fi if [[ -n $OPENSSH_PRIVATE_KEY ]]; then git add nix/sources.json @@ -66,6 +69,8 @@ with lib; { GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" \ git push gitea master fi + + wait ''${CACHIX_PUSH-} fi else echo "no source changes" >&2 diff --git a/default.nix b/default.nix index 1b4ae31a..f5393170 100644 --- a/default.nix +++ b/default.nix @@ -19,8 +19,16 @@ rec { runners = import ./runners.nix { inherit lib; inherit (deploy) target; }; - getSources = sources: lib.attrValues (lib.removeAttrs sources [ "__functor" ]); - sourceCache = map(value: if lib.isDerivation value.outPath then value.outPath else value) (getSources sources ++ getSources (import sources.nix-hexchen {}).sources); + sourceCache = with lib; let + getSources = sources: removeAttrs sources [ "__functor" "dorkfiles" ]; + source2drv = value: if isDerivation value.outPath then value.outPath else value; + sources2drvs = sources: mapAttrs (_: source2drv) (getSources sources); + in recurseIntoAttrs rec { + local = sources2drvs sources; + hexchen = sources2drvs (import sources.nix-hexchen {}).sources; + all = attrValues local ++ attrValues hexchen; + allStr = toString all; + }; deploy = import ./lib/deploy.nix { inherit pkgs sources;