Created
September 10, 2017 21:01
-
-
Save infinisil/0019c20e2cb1a06aac40b0fca760ee17 to your computer and use it in GitHub Desktop.
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
rec { | |
pkgs = import <nixpkgs> {}; | |
lib = pkgs.lib; | |
attrToDerivation = name: value: let | |
valToPath = name: value: if builtins.isAttrs value then '' | |
mkdir "${name}" && pushd "${name}" | |
${lib.concatMapStringsSep "\n" (attrName: valToPath attrName value.${attrName}) (builtins.attrNames value)} | |
popd | |
'' else '' | |
cp "${value}" "${name}" | |
''; | |
fileAttrSet = lib.mapAttrsRecursive (path: builtins.toFile (lib.concatStringsSep "-" path)) value; | |
in pkgs.runCommand name { | |
preferLocalBuild = true; | |
} (valToPath "$out" fileAttrSet); | |
res = attrToDerivation "example" { | |
foo = "Hello"; | |
bar = { | |
baz = "There"; | |
qux = ":D"; | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment