This module creates a script and exposes it in environment.systemPackages so you can easily interact with the deployed site.
Now to my problem: for some projects I need to regularly execute tasks that should call this script with some arguments. I know I can do this with a systemd timer, but apparently I need to specify the absolute path to the executable in the service file. But since the executable is created in the NixOS module, I can’t access it from my system configuration file.
So, how can I get the path to a derivation created in my module? Or how can I somehow expose it?
Note the script needs to be generated by the NixOS module because it contains stuff like environment variables and references to other Python libs, so I can’t just add a manageScript option to the module and pass the derivation from the caller.
I didn’t know about read-only options (it seems the NixOS manual doesn’t mention them?) but from what I could see in the code, it’s just a matter of passing readOnly = true to mkOption, right? So my option would look like this:
Move the mapAttrs lower in the attribute path. Nix can’t tell without evaluating it that it doesn’t set some other options (like the inputs to siteConfigs itself), and it can’t evaluate it without having final values for those options, so it creates an infinite recursion.
Then move the logic into the submodule itself? A submodule behaves like an independent invocation of the module system during merge, so you can actually write “modules” that work at its level. Home-manager does this, for example, that’s why you can import normal home-manager modules when using it as a nixos module.
I remembered the php-fpm module uses a similar syntax to what I’m trying to achieve and has a read-only socket option defined by the module itself. It’s done by passing a callable to the submodule option, where you get the name of the attr (ie. the site to configure).
submodule is a very powerful type that defines a set of sub-options that are handled like a separate module.
It takes a parameter o , that should be a set, or a function returning a set with an options key defining the sub-options. Submodule option definitions are type-checked accordingly to the options declarations. Of course, you can nest submodule option definitons for even higher modularity.
Surprisingly there is no information on what parameters are passed to the submodule function. If anyone knows this, I’d be interested to know!