Created
November 6, 2018 15:28
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ 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