]>
Commit | Line | Data |
---|---|---|
a9d77a20 FM |
1 | { pkgs, toExeName ? (e: if pkgs.lib.hasInfix "/" e.exeName then e.exeName else "bin/${e.exeName}") }: |
2 | let | |
3 | nix-bundle = import (builtins.fetchTarball "https://github.com/matthewbauer/nix-bundle/archive/master.tar.gz") {}; | |
4 | toNixBundle = e: if pkgs.lib.isDerivation e then | |
5 | nix-bundle.nix-bootstrap { | |
6 | target = e; | |
7 | run = "/${toExeName e}"; | |
8 | nixUserChrootFlags = "-m /builds:/builds"; | |
9 | } else e; | |
10 | in | |
11 | { | |
12 | # This function takes an (possibly deep) attrset of derivations and | |
13 | # turns those derivations into bundles, returning the same attrset | |
14 | bundled-derivations = pkgs.lib.mapAttrsRecursiveCond | |
15 | (f: !builtins.isBool f && !(pkgs.lib.isDerivation f)) | |
16 | (_: toNixBundle); | |
17 | # This function collects all the derivations of an attrset, and | |
18 | # turns them into a directory of executable bundles. | |
19 | bundled-dist = derivations: pkgs.runCommand "dist" {} '' | |
20 | mkdir -p $out/bin | |
21 | ${builtins.concatStringsSep "\n" | |
22 | (map | |
23 | (b: "cp ${toNixBundle b} $out/${toExeName b}") | |
24 | (pkgs.lib.collect pkgs.lib.isDerivation derivations) | |
25 | )} | |
26 | ''; | |
27 | bundled-documentation = derivations: pkgs.runCommand "documentation" {} '' | |
28 | mkdir -p $out/share/doc | |
29 | ${builtins.concatStringsSep "\n" | |
30 | (map | |
31 | (b: '' | |
32 | for f in ${b}/share/doc/*; do | |
33 | cp -a "$f/html" $out/share/doc/$(basename "$f") | |
34 | done | |
35 | '') | |
36 | (pkgs.lib.collect pkgs.lib.isDerivation derivations) | |
37 | )} | |
38 | ''; | |
39 | # This function collects all the derivations of an attrset, and | |
40 | # turns them into a tarball of executable bundles. | |
41 | tarball = derivations: pkgs.runCommand "bundled.tar.gz" {} '' | |
42 | tar -Pczf $out ${builtins.concatStringsSep " " | |
43 | (map | |
44 | (b: "--transform=s@${toNixBundle b}@${toExeName b}@ ${toNixBundle b}") | |
45 | (pkgs.lib.collect pkgs.lib.isDerivation derivations) | |
46 | )} | |
47 | ''; | |
48 | } |