The use case is related to Xorg:
By default an xorg.conf is generated by using a template and filling in configuration values. In my setup, the option services.xserver.config which holds the text is defined in <nixos/nixos/modules/services/x11/xserver.nix> (where it is declared) and in <nixos/nixos/modules/services/x11/hardware/synaptics.nix>. The option is of type line, which means that multiple definitions are appended, interspersed by newlines, becoming a single string.
Now I want to override (in fact remove) the part generated by xserver.nix to get auto detection for my graphics hardware while preserving the settings by synaptics.nix. In other words, I want to hide the definition by xserver.nix, preserving all other definitions.
If I override it using services.xserver.config = mkOverride 0 "" then the whole content is deleted because only the definitions with the least priority are applied.
Therefore I tried disabling the xserver module and importing it again in a wrapper module, hiding the single option:
# xserver.nix # wrapper module
args@{ lib, pkgs, pkgs_i686, config, ... }:
let
super = import <nixos/nixos/modules/services/x11/xserver.nix> args;
in lib.recursiveUpdate super {
imports = []; # the imports are not disabled recursively by disabling
# the including module in the following:
disabledModules = [ "services/x11/xserver.nix" ];
config.services.xserver.config = "";
}
This did not change anything.
So I tried the following:
# xserver2.nix # wrapper module 2
args@{ lib, pkgs, pkgs_i686, config, ... }:
let
super = import <nixos/nixos/modules/services/x11/xserver.nix> args;
in {
options = super.options;
disabledModules = [ "services/x11/xserver.nix" ];
config = lib.recursiveUpdate super.config {
services.xserver.config = "";
};
}
This didn't change anything either. Somehow the old definition still gets exported. NixOS configuration seems mysteriously stateful!?!?
Is there any possibility to achieve what I want without forking the package?
I think this is due to merges in the NixOS module system. I put your wrappers into
nix-repland as you say they do not override the config fromservices/x11/xserver.nix. However inwrapper2I altered theconfigthat's passed toservices/x11/xserver.nixand that does override thexserver.nixconfig.Here's the (cut down) output from nix-repl:
I think that the
configin your initial wrappers are being merged somehow withconfigthat don't have theservices/x11/xserver.nixmodule disabled, and so your changes are just getting overridden again.Unless anyone else has a more helpful answer for your question here then it might be helpful for you to ask in the NixOS IRC channel, otherwise you could always look through the NixOS module system source to try and work out how best to handle overriding the
xserver.nixconfig(the source is a bit of a headache at first but once you get your head round the recursion it is not too bad).