Skip to content

Instantly share code, notes, and snippets.

@Profpatsch
Created November 6, 2018 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Profpatsch/4b1eadbe2ff3a9b7596997e3b29589c0 to your computer and use it in GitHub Desktop.
Save Profpatsch/4b1eadbe2ff3a9b7596997e3b29589c0 to your computer and use it in GitHub Desktop.
Import all subfiles of a bazel local cache (content-addressable hash for each artifact) into the nix store, one derivation each
{ nixpkgs ? import <nixpkgs> {} }:
let
inherit (nixpkgs) lib;
importBazelLocalCache = cacheDir:
let
fileList = lib.mapAttrs
(dirname: type:
# sanity check
assert lib.assertMsg (type == "directory" || type == "regular")
"${dirname} is of type ${type}, which is not supported";
# prepend cache dir
builtins.path { path = cacheDir + ("/" + dirname); })
(builtins.readDir cacheDir);
in
nixpkgs.runCommand "bazel-cache" {} (''
mkdir $out
''
+ (lib.concatStringsSep "\n"
(lib.mapAttrsToList
(dirname: path:
"ln -s ${lib.escapeShellArg path} " # <- space
+ "$out/${lib.escapeShellArg dirname}")
fileList)));
in
importBazelLocalCache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment