Skip to content

Commit

Permalink
Regenerate the files transparently when entering the dev shell
Browse files Browse the repository at this point in the history
Removes the need from running `regenerate-files` manually
  • Loading branch information
Théophane Hufschmitt committed Jun 21, 2024
1 parent b0585da commit 4fce4b7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 4 additions & 1 deletion doc/filegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ This has two main advantages:

## Usage

To re-generate the files run:
The files specified in `files.*` are regenerated automatically when entering
the devshell (unless `filegen_hook` is set to false).

They can also be regenerated manually with:

```bash
nix run .#regenerate-files
Expand Down
21 changes: 21 additions & 0 deletions lib/files.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,31 @@ let regenerate_files | Files -> nix.derivation.Derivation = fun files_to_generat
Set of files that should be generated in the project's directory.
"%
= {},
filegen_hook.enable
| Bool
| doc m%"
Enable a hook that will automatically regenerate the files managed by
Nickel when entering the shell.
"%
| default
= true,
flake.apps, # Forward declaration. Not great but would need some refactor to fix
shells,
},
config | Schema = {
files,
filegen_hook,
shells,
flake.apps.regenerate-files.program = nix-s%"%{regenerate_files files}/bin/regenerate-files"%,

shells.build.hooks =
if filegen_hook.enable then
{
filegen_hook = nix-s%"
%{regenerate_files files}/bin/regenerate-files
"%
}
else
{},
},
}
1 change: 0 additions & 1 deletion run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ test_example () (
cp -r "$examplePath" ./example
pushd ./example
prepare_shell
nix run .\#regenerate-files --print-build-logs
nix develop --print-build-logs --command bash test.sh
popd
popd
Expand Down

0 comments on commit 4fce4b7

Please sign in to comment.