From 4fce4b7f99f1068c757b486f45befc1560b05c43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Fri, 24 May 2024 08:33:31 +0200 Subject: [PATCH] Regenerate the files transparently when entering the dev shell Removes the need from running `regenerate-files` manually --- doc/filegen.md | 5 ++++- lib/files.ncl | 21 +++++++++++++++++++++ run-test.sh | 1 - 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/doc/filegen.md b/doc/filegen.md index 13a486e7..3ce356a9 100644 --- a/doc/filegen.md +++ b/doc/filegen.md @@ -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 diff --git a/lib/files.ncl b/lib/files.ncl index c6b0ea8d..f30e9fc6 100644 --- a/lib/files.ncl +++ b/lib/files.ncl @@ -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 + {}, }, } diff --git a/run-test.sh b/run-test.sh index 0c44ac02..1d2882e5 100755 --- a/run-test.sh +++ b/run-test.sh @@ -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