Skip to content
Snippets Groups Projects

Construct a better Nix store cache key for CircleCI

Merged Jean-Paul Calderone requested to merge 15.circleci-cache-key into master
1 file
+ 30
8
Compare changes
  • Side-by-side
  • Inline
+ 30
8
@@ -42,6 +42,23 @@ jobs:
@@ -42,6 +42,23 @@ jobs:
command: |
command: |
echo "export NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/$NIXPKGS_REV.tar.gz" >> $BASH_ENV
echo "export NIX_PATH=nixpkgs=https://github.com/NixOS/nixpkgs/archive/$NIXPKGS_REV.tar.gz" >> $BASH_ENV
 
# Get *our* source code.
 
- "checkout"
 
 
- "run":
 
# CircleCI won't let us interpolate NIXPKGS_REV into a cache key.
 
# Only CircleCI's own environment variables or variables set via the
 
# web interface in a "context" can be interpolated into cache keys.
 
# However, we can interpolate the checksum of a file... Since we
 
# don't care about the exact revision, we just care that a new
 
# revision gives us a new string, we can write the revision to a
 
# file and then put the checksum of that file into the cache key.
 
# This way, we don't have to maintain the nixpkgs revision in two
 
# places and risk having them desynchronize.
 
name: "Prepare For Cache Key"
 
command: |
 
echo "${NIXPKGS_REV}" > nixpkgs.rev
 
- restore_cache:
- restore_cache:
# Get all of Nix's state relating to the particular revision of
# Get all of Nix's state relating to the particular revision of
# nixpkgs we're using. It will always be the same. CircleCI
# nixpkgs we're using. It will always be the same. CircleCI
@@ -54,16 +71,21 @@ jobs:
@@ -54,16 +71,21 @@ jobs:
# Read about caching dependencies: https://circleci.com/docs/2.0/caching/
# Read about caching dependencies: https://circleci.com/docs/2.0/caching/
name: "Restore Nix Store Paths"
name: "Restore Nix Store Paths"
keys:
keys:
# This doesn't work right. "<no value>" is interpolated in,
# Construct cache keys that allow sharing as long as nixpkgs and
# instead of the value for NIXPKGS_REV set above.
# the Ristretto library are the same.
#
#
# https://github.com/PrivateStorageio/PaymentServer/issues/15
# If the Ristretto library changes, we have to rebuild it so we
- paymentserver-nix-store-v1-{{ .Environment.NIXPKGS_REV }}
# may as well throw away the part of the cache with the old build
 
# and make a new one with the new build so we don't have to
 
# rebuild it *again* next time.
 
#
 
# If nixpkgs changes then potentially a lot of cached packages for
 
# the base system will be invalidated so we may as well drop them
 
# and make a new cache with the new packages.
 
- paymentserver-nix-store-v1-{{ checksum "nixpkgs.rev" }}-{{ checksum "ristretto.nix" }}
 
- paymentserver-nix-store-v1-{{ checksum "nixpkgs.rev" }}-
- paymentserver-nix-store-v1-
- paymentserver-nix-store-v1-
# Get *our* source code.
- "checkout"
- restore_cache:
- restore_cache:
# Restore the cache of Stack's state. This will have all of the
# Restore the cache of Stack's state. This will have all of the
# compiled Haskell libraries we depend on and even the compiled
# compiled Haskell libraries we depend on and even the compiled
@@ -136,7 +158,7 @@ jobs:
@@ -136,7 +158,7 @@ jobs:
- save_cache:
- save_cache:
name: "Cache Nix Store Paths"
name: "Cache Nix Store Paths"
key: paymentserver-nix-store-v1-{{ .Environment.NIXPKGS_REV }}
key: paymentserver-nix-store-v1-{{ checksum "nixpkgs.rev" }}-{{ checksum "ristretto.nix" }}
paths:
paths:
- "/nix"
- "/nix"
Loading