Hi Nixers,
I am building a nix os module and stumbled upon a problem which I
might need your advice on how to approach it.
What I can't figure out, is how to filter out unset values even if
they don't have a default value set in mkOption. The idea is that
application itself handles missing values using defaults and I don't
want to duplicate them in a config.
On the other hand, there are some values which are mandatory, so that
if they are missing from configuration.nix config build should fail.
Worth mentioning is that number of mandatory attrs is << number of
handled by default attrs, so I'd prefer to whitelist mandatories if it
is possible. Also the solution whatever it is should process cfg
recursively as cfg is actually nested set of types.submodules.
Here is a minimal example, which demonstrates the problem I am trying
to solve. It doesn't make sense overall, so don't judge me for missing
mkIf or silly system services ;) it just shows what I am trying to
achieve.
{ config, lib, pkgs, ... }:
with lib;
let
# question is how to write this function
filter_cfg = cfg: cfg;
cfg = filter_cfg config.services.xyz;
confFile = pkgs.writeText "xyz.json" (builtins.toJSON cfg);
in
{
options.services.xyz = {
opt1 = mkOption { type = types.str; default="default_opt1"; };
# should be excluded from cfg if missing in configuration
opt_devs_defaults = mkOption { type = types.str; };
# error should be raised if missing in conf
opt_mandatory = mkOption { type = types.str; };
};
config = {
systemd.services.xyz = {
serviceConfig = {
ExecStart = "${pkgs.bash} -c 'touch ${confFile}'";
};
};
};
}
_______________________________________________
nix-dev mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-dev