Add --cache flag to bild for signing and pushing closures to S3.
Omni/Bild.hs - Add --cache flag and cache functionsOptions:
--cache, -C Sign and push to S3 binary cache after build
-- | Sign and push a store path to S3 cache
cacheStorePath :: FilePath -> IO ()
cacheStorePath storePath = do
keyPath <- Env.lookupEnv "NIX_CACHE_KEY"
case keyPath of
Nothing -> Log.warn ["cache", "NIX_CACHE_KEY not set, skipping cache"]
Just key -> do
let s3Url = "s3://omni-nix-cache?profile=digitalocean&scheme=https&endpoint=nyc3.digitaloceanspaces.com"
-- Sign
(exitSign, _, _) <- Process.readProcessWithExitCode "nix"
["store", "sign", "--key-file", key, storePath] ""
case exitSign of
ExitSuccess -> do
-- Push
(exitPush, _, _) <- Process.readProcessWithExitCode "nix"
["copy", "--to", s3Url, storePath] ""
case exitPush of
ExitSuccess -> Log.good ["cache", "pushed", str storePath]
_ -> Log.fail ["cache", "push failed", str storePath]
_ -> Log.fail ["cache", "sign failed", str storePath]
-- After successful build, if --cache flag set:
when (isCache && isSuccess (fst result)) do
cacheStorePath (nixdir </> outname out)
When --cache is set, print the store path to stdout after caching.
export NIX_CACHE_KEY=~/.config/nix/cache-priv-key.pem
bild --cache Biz/PodcastItLater/Web.py
# Should output store path and push to S3