From 192f123e4b5a4605c30566409ccacffc416e45c4 Mon Sep 17 00:00:00 2001 From: Michael Hoang Date: Sat, 16 Nov 2024 17:31:16 +0000 Subject: [PATCH] nixos: add `key` to shared module to allow disabling it (#6017) By adding `key`, this allows users to disable this shared module or they can choose to not disable this shared module (by filtering by key before disabling) This means users can disable all shared modules if all modules are paths or attrsets with a key: `configuration.nix`: ```nix { config, ... }: { home-manager.users.enzime = { ... }: { disabledModules = config.home-manager.sharedModules; }; } ``` Or disabling just this module specifically: ```nix { ... }: { home-manager.users.enzime = { ... }: { disabledModules = [ { key = "home-manager#nixos-shared-module"; } ]; }; } ``` Or disabling all modules when you have modules you can't disable (like lambdas): ```nix { ... }: { home-manager.users.enzime = { ... }: { disabledModules = lib.filter (v: lib.isString v || lib.isPath v || (lib.isAttrs v && v ? key)) config.home-manager.sharedModules; }; } ``` https://nixos.org/manual/nixos/unstable/#sec-replace-modules --- nixos/default.nix | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/nixos/default.nix b/nixos/default.nix index 2b542238a..4484d28f8 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -19,13 +19,17 @@ in { extraSpecialArgs.nixosConfig = config; sharedModules = [{ - # The per-user directory inside /etc/profiles is not known by - # fontconfig by default. - fonts.fontconfig.enable = lib.mkDefault - (cfg.useUserPackages && config.fonts.fontconfig.enable); + key = "home-manager#nixos-shared-module"; - # Inherit glibcLocales setting from NixOS. - i18n.glibcLocales = lib.mkDefault config.i18n.glibcLocales; + config = { + # The per-user directory inside /etc/profiles is not known by + # fontconfig by default. + fonts.fontconfig.enable = lib.mkDefault + (cfg.useUserPackages && config.fonts.fontconfig.enable); + + # Inherit glibcLocales setting from NixOS. + i18n.glibcLocales = lib.mkDefault config.i18n.glibcLocales; + }; }]; }; }