1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2024-12-14 11:57:55 +00:00

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
This commit is contained in:
Michael Hoang 2024-11-16 17:31:16 +00:00 committed by GitHub
parent 400e3c0152
commit 192f123e4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,6 +19,9 @@ in {
extraSpecialArgs.nixosConfig = config; extraSpecialArgs.nixosConfig = config;
sharedModules = [{ sharedModules = [{
key = "home-manager#nixos-shared-module";
config = {
# The per-user directory inside /etc/profiles is not known by # The per-user directory inside /etc/profiles is not known by
# fontconfig by default. # fontconfig by default.
fonts.fontconfig.enable = lib.mkDefault fonts.fontconfig.enable = lib.mkDefault
@ -26,6 +29,7 @@ in {
# Inherit glibcLocales setting from NixOS. # Inherit glibcLocales setting from NixOS.
i18n.glibcLocales = lib.mkDefault config.i18n.glibcLocales; i18n.glibcLocales = lib.mkDefault config.i18n.glibcLocales;
};
}]; }];
}; };
} }