diff --git a/lib/builders.ncl b/lib/builders.ncl index 2110da89..5e7c7f93 100644 --- a/lib/builders.ncl +++ b/lib/builders.ncl @@ -179,4 +179,51 @@ in env.content = content, } | NixpkgsPkg, + FileTree + | doc m%" + Turn a record of derivations the form + + ``` + { + "path1" = drv1, + "path2/with/subpath" = drv2, + } + ``` + + to a single derivation whose content is a tree of symlinks of the form + + ``` + |- path1 -> drv1 + |- path2 + |- with + |- subpath -> drv2 + ``` + "% + = + { + input_paths | { _ : NixString }, + # TODO: Sanity-check the inputs + # - Escape the values + # - Raise a proper error is there's some overlap between the + # paths + env.buildCommand = nix-s%" + mkdir -p "$out" + cd "$out" + %{ + std.record.to_array input_paths + |> std.array.fold_right + (fun { field, value } acc => + nix-s%" + mkdir -p "$(dirname '%{field}')" + ln -s '%{value}' '%{field}' + + %{acc} + "% + ) + "" + } + "%, + version = "0.0", + } + | NixpkgsPkg } diff --git a/tests/FileTree.ncl b/tests/FileTree.ncl new file mode 100644 index 00000000..1251004e --- /dev/null +++ b/tests/FileTree.ncl @@ -0,0 +1,30 @@ +let organist = import "../lib/nix.ncl" in +let paths = { + "bin/hello" = organist.lib.import_file "tests/hello.sh", + "README.md" = + organist.builders.TextFile + & { + name = "README", + content = "Hello package", + }, +} +in +let file_tree = + organist.builders.FileTree + & { + name = "foobar", + input_paths = paths, + } +in +organist.builders.NixpkgsPkg +& { + name = "test-filetree", + version = "0.1", + env.buildCommand = + nix-s%" + [[ $(realpath '%{file_tree}/bin/hello') == $(realpath '%{paths."bin/hello"}') ]] + [[ $(realpath '%{file_tree}/README.md') == $(realpath '%{paths."README.md"}') ]] + echo "OK" > $out + "% + | organist.contracts.NixString, +} diff --git a/tests/TextFile.ncl b/tests/TextFile.ncl index 49f84362..cba47a8f 100644 --- a/tests/TextFile.ncl +++ b/tests/TextFile.ncl @@ -1,6 +1,7 @@ let organist = import "../lib/nix.ncl" in -let - someText = organist.builders.TextFile & { +let someText = + organist.builders.TextFile + & { name = "foo", content = "Heyio" } @@ -16,4 +17,3 @@ organist.builders.NixpkgsPkg "% | organist.contracts.NixString, } - \ No newline at end of file diff --git a/tests/main.ncl b/tests/main.ncl index e0fb7bfe..cdfb5c26 100644 --- a/tests/main.ncl +++ b/tests/main.ncl @@ -1,4 +1,5 @@ { ShellApplication = import "ShellApplication.ncl", - TextFile = import "TextFile.ncl" -} \ No newline at end of file + TextFile = import "TextFile.ncl", + FileTree = import "FileTree.ncl", +}