Skip to content

Instantly share code, notes, and snippets.

@infinisil
Created September 10, 2017 21:01
Show Gist options
  • Save infinisil/0019c20e2cb1a06aac40b0fca760ee17 to your computer and use it in GitHub Desktop.
Save infinisil/0019c20e2cb1a06aac40b0fca760ee17 to your computer and use it in GitHub Desktop.
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