Skip to content

Instantly share code, notes, and snippets.

@infinisil
Created September 10, 2017 19:55
Show Gist options
  • Save infinisil/7b0879ae420147805815ec6eb0b5dc14 to your computer and use it in GitHub Desktop.
Save infinisil/7b0879ae420147805815ec6eb0b5dc14 to your computer and use it in GitHub Desktop.
let
pkgs = import <nixpkgs> {};
lib = pkgs.lib;
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 ''
echo "${toString value}" > "${name}"
'';
attrToDerivation = name: attrs: pkgs.runCommand name {} (valToPath "$out" attrs);
in
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