Skip to content

Commit

Permalink
Add a FileTree builder
Browse files Browse the repository at this point in the history
Builder that takes a mapping `path -> target` (as a Nickel record) and
builds a tree of symlinks corresponding to that mapping (the
documentation of the function itself might be a bit clearer).
  • Loading branch information
Théophane Hufschmitt committed Sep 29, 2023
1 parent eaed736 commit f5e0b74
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 5 deletions.
47 changes: 47 additions & 0 deletions lib/builders.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
30 changes: 30 additions & 0 deletions tests/FileTree.ncl
Original file line number Diff line number Diff line change
@@ -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,
}
6 changes: 3 additions & 3 deletions tests/TextFile.ncl
Original file line number Diff line number Diff line change
@@ -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"
}
Expand All @@ -16,4 +17,3 @@ organist.builders.NixpkgsPkg
"%
| organist.contracts.NixString,
}

5 changes: 3 additions & 2 deletions tests/main.ncl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
ShellApplication = import "ShellApplication.ncl",
TextFile = import "TextFile.ncl"
}
TextFile = import "TextFile.ncl",
FileTree = import "FileTree.ncl",
}

0 comments on commit f5e0b74

Please sign in to comment.