Skip to content

Commit

Permalink
Allow specifying a source file in files.*
Browse files Browse the repository at this point in the history
This is in particular useful when the source file is generated with Nix.
Use for instance with:

```nickel
{
    files."foo".file = nix.import_nix "nixpkgs#foo",
}
```
  • Loading branch information
Théophane Hufschmitt committed Jun 21, 2024
1 parent 4fce4b7 commit 1b4c9ca
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/files.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ let File = {
| doc m%"
The content of the file.
"%
| nix.derivation.NixString,
| nix.derivation.NullOr nix.derivation.NixString
| default
= null,
file
| doc "File from which to read the body of the script"
| nix.derivation.NullOr nix.derivation.NixString
| default
=
if content == null then
null
else
nix.builtins.to_file "generated-content" content,
materialisation_method
: [| 'Symlink, 'Copy |]
| doc m%"
Expand Down Expand Up @@ -51,8 +62,11 @@ let regenerate_files | Files -> nix.derivation.Derivation = fun files_to_generat
nix-s%"
rm -f %{target}
echo "Regenerating %{target}"
target_dir=$(dirname %{target})
test "${target_dir}" != "." && mkdir -p "${target_dir}"
target_dir=$(dirname %{target})
test "${target_dir}" != "." && mkdir -p "${target_dir}"
# XXX: If `source.file` is set explicitely to a relative path
# and `materialisation_method` is `'Symlink`, this will link to the
# original file, not one in the store. Not sure that's what we want.
%{copy_command} %{file_in_store} %{target}
"%
in
Expand Down

0 comments on commit 1b4c9ca

Please sign in to comment.