Override submodule options

Hi there. Is there a way to override options nested inside an option of type = attrsOf (submodule ...)? I want to add an extra attribute to networking.interfaces.<name>. Is there a way to do this without editing the original source file?

I’m interested in this too, I needed to do something similar in editing options of ohMyZsh module, in the end I did as the Replace Modules manual section suggests. I hid the “original” module, imported my custom one in my configuration.nix file and used it, however I couldn’t figure out how to change just bits of the code, I shamelessly copied the original, did my modifications on it and imported that.
Although not ideal, until I find something better this gets the work done.

There was an issue opened on nixpkgs a while ago on this very topic, but adding this functionality seems to have been overly complex and it was closed. The current workaround, as @zzantares described, is disabling the old module completely in disabledModules and then making a copy of it with your extensions added in.

Turns out it was easier than expected, you just need to redefine the attrsOf option, and it looks like the module system will take care of merging the sub-options:

{ config, lib, ... }:
with lib;
let
  interfaceModule = { name, config, ... }:
    {
      options = {
        myNewOption = mkOption {
          type = types.str;
        };
      };
    };
in
{
    options = {
      networking.interfaces = mkOption {
        type = types.attrsOf (types.submodule interfaceModule);
      };
    };
}
6 Likes