Open wuyoli opened 1 year ago
I tried generating the template dynamically by defining a derivation and setting templates.<name>.path = testTemplateDrv
in different similar configurations, but it didn't work.
templates.<name>.path = testTemplateDrv
-> error: 'templates.<name>.path' is not a string but a set
templates.<name>.path = testTemplateDrv.out
-> error: 'templates.<name>.path' is not a string but a set
templates.<name>.path = testTemplateDrv.outPath
-> error: 'templates.<name>.path' is not a string but a set
templates.<name>.path = "${testTemplateDrv}"
-> error: opening directory '/nix/store/ipsmqp2yayjijb7mbnd2mk1bc6zwfp9x-test': No such file or directory
I tried generating the template dynamically by defining a derivation and setting
templates.<name>.path = testTemplateDrv
in different similar configurations, but it didn't work.templates.<name>.path = testTemplateDrv
->error: 'templates.<name>.path' is not a string but a set
templates.<name>.path = testTemplateDrv.out
->error: 'templates.<name>.path' is not a string but a set
templates.<name>.path = testTemplateDrv.outPath
->error: 'templates.<name>.path' is not a string but a set
templates.<name>.path = "${testTemplateDrv}"
->error: opening directory '/nix/store/ipsmqp2yayjijb7mbnd2mk1bc6zwfp9x-test': No such file or directory
As far as I can tell the path has to be path inside the nix store itself and not a derivation. But if you have a derivation you should be able to call drvPath
on it.
Problem
I want to make a template for programming in in a environment managed by a nix Flake. This works pretty good with the
templates.<name>
output. However, it is still a bit clumsy to use:nix flake init -t myTemplateFlake#templateName
git init
git add .
to make nix aware of all required filesnix develop
to enter the development environmentSolutions
script
optionI want to suggest to add a
templates.<name>.script
option which takes a path to a script (or a string containing a script) which is executed after the content oftemplates.<name>.path
is copied to the target folder. This allows the creators of the template to decide, what they want to do (they might implement steps 1-4 of the above list) and prompt the user for possible inputs. But this might be problematic in regards to the pure and reproducible environment.specialized options for every aspect
this would mean implementing many options like:
templates.<name>.initGit
to decide, whether to automatically init a git repositorytemplates.<name>.replace
as a list of strings, which will automatically be replaced. Their replacement value could be given to them in the call ofnix init
:nix init -t myTemplateFlake#templateName --replace <string>=<futureString>
, but this could break the environment again.