1 { pkgs, toExeName ? (e: if pkgs.lib.hasInfix "/" e.exeName then e.exeName else "bin/${e.exeName}") }:
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 {
7 run = "/${toExeName e}";
8 nixUserChrootFlags = "-m /builds:/builds";
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))
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" {} ''
21 ${builtins.concatStringsSep "\n"
23 (b: "cp ${toNixBundle b} $out/${toExeName b}")
24 (pkgs.lib.collect pkgs.lib.isDerivation derivations)
27 bundled-documentation = derivations: pkgs.runCommand "documentation" {} ''
28 mkdir -p $out/share/doc
29 ${builtins.concatStringsSep "\n"
32 for f in ${b}/share/doc/*; do
33 cp -a "$f/html" $out/share/doc/$(basename "$f")
36 (pkgs.lib.collect pkgs.lib.isDerivation derivations)
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 " "
44 (b: "--transform=s@${toNixBundle b}@${toExeName b}@ ${toNixBundle b}")
45 (pkgs.lib.collect pkgs.lib.isDerivation derivations)