I have custom modules that I enable for a NixOS system. E.g.
# modules/nixos/tools/direnv/default.nix
{ options, config, lib, pkgs, namespace, ... }:
with lib;
with lib.${namespace}; let
cfg = config.${namespace}.tools.direnv
in {
options.${namespace}.tools.direnv = with types; {
enable = mkBoolOpt false "Whether or not to enable direnv.";
};
config =
mkIf cfg.enable {
mypkgs.home.extraOptions = {
programs.direnv = {
enable = true;
nix-direnv = enabled;
};
};
};
}
I enable this in my systems configuration like so, options.mypkgs.tools.direnv.enable = true;
I then want to update the code of the module to have more arguments, or optimise in some way, etc.
# updated modules/nixos/tools/direnv/default.nix
{ options, config, lib, pkgs, namespace, ... }:
with lib;
with lib.${namespace}; let
cfg = config.${namespace}.tools.direnv;
in {
options.${namespace}.tools.direnv = with types; {
enable = mkBoolOpt false "Whether or not to enable direnv.";
# Added new option
foobar.enable = mkBoolOpt false "Whether or not to enable direnv foobar.";
};
config =
mkIf cfg.enable {
mypkgs.home.extraOptions = {
programs.direnv = {
enable = true;
# Added config for new option
foobar mkIf cfg.foobar.enable = true;
};
};
};
}
How can I check that given the same inputs to the options I get the same result? In this example, I’m checking that the old systems don’t need to all be updated with foobar.enable = false
;
I’ve looked at a few things, including namaka which suggested it could do snapshot testing like this, but I couldn’t get it to work for the nixosConfiguration. Nix eval can do it at some levels of the flake, but not the whole config, and a wrapper around that didn’t feel scalable.