-
-
Save MichaelXavier/eeaaf602e6e178f769cf826937660513 to your computer and use it in GitHub Desktop.
fixed output derivation
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
# Given a set of exact npm packages to install, produces a set of | |
# expressions. e.g. if you provide {"foo" = "1.2.3.4";}, it will | |
# return {"foo-1.2.3.4" = {..derivation}}. If you depend on the | |
# derivation, it will make any executables from that dependency | |
# available to your build shell. To avoid having to redundantly pluck | |
# out exact versions from the set, if you just want a list of | |
# derivations to add to your buildInputs, I recommend passing the | |
# result through builtins.attrValues. | |
{ # Set of exact versions to install, e.g. {"typescript" = "1.5.3";} | |
# TODO: how could i get this to recompute when nodeDeps changes? | |
nodeDeps ? {} | |
# Name of this derivation | |
, name | |
, outputHash | |
# Which major version of node are you using? | |
, nodeVersion ? "10" | |
, pkgs | |
# Optional, pulls from pkgs based on nodeVersion if not specified | |
, nodePackages ? pkgs."nodePackages_${nodeVersion}_x" | |
# Optional, pulls from pkgs based on nodeVersion if not specified | |
, nodejs ? pkgs."nodejs-${nodeVersion}_x" | |
}: | |
let | |
# {"foo" = "1.2.3"; "bar" = "4.5.6"} => [{"foo" = "1.2.3";}, {"bar" = "4.5.6";}] | |
depsList = builtins.map | |
(attr: builtins.listToAttrs | |
[{ name = attr; | |
value = builtins.getAttr attr nodeDeps;}]) | |
(builtins.attrNames nodeDeps); | |
# The output gives us a directory with some expressions in it | |
exprs = pkgs.runCommand name { | |
inherit outputHash; | |
# we're outputting a tree of files here, so "flat" is not the right choice | |
outputHashMode = "recursive"; | |
outputHashAlgo = "sha256"; | |
buildInputs = [ | |
#TODO: why don't arguments recompute? | |
nodeDeps | |
nodePackages.node2nix | |
]; | |
} '' | |
set -e | |
mkdir -p $out | |
echo '${builtins.toJSON depsList}' > input.json | |
node2nix --input input.json --composition $out/default.nix --node-env $out/node-env.nix --output $out/node-packages.nix --nodejs-${nodeVersion} | |
''; | |
in | |
# Take the output expressions and import them, yielding derivations for the required packages | |
import exprs { | |
inherit pkgs; | |
inherit nodejs; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment