Possible to programatically make variant of existing NixOS module?

I’m pretty sure this function in <nixpkgs/lib/modules.nix> does exactly what you want:

538   # Convenient property used to transfer all definitions and their
539   # properties from one option to another. This property is useful for
540   # renaming options, and also for including properties from another module
541   # system, including sub-modules.
542   #
543   #   { config, options, ... }:
544   #
545   #   {
546   #     # 'bar' might not always be defined in the current module-set.
547   #     config.foo.enable = mkAliasDefinitions (options.bar.enable or {});
548   #
549   #     # 'barbaz' has to be defined in the current module-set.
550   #     config.foobar.paths = mkAliasDefinitions options.barbaz.paths;
551   #   }
552   #
553   # Note, this is different than taking the value of the option and using it
554   # as a definition, as the new definition will not keep the mkOverride /
555   # mkDefault properties of the previous option.
556   #
557   mkAliasDefinitions = mkAliasAndWrapDefinitions id;
558   mkAliasAndWrapDefinitions = wrap: option:
559     mkIf (isOption option && option.isDefined) (wrap (mkMerge option.definitions));
1 Like