Auto-enable home-manager integration when hm is available

This commit is contained in:
DwarfMaster 2023-02-01 21:38:01 +01:00
parent 638f2d86c4
commit 83456eceb6
2 changed files with 29 additions and 8 deletions

View file

@ -23,7 +23,10 @@ in {
Doesn't do anything if the home-manager configuration is not used
from NixOS.
'';
default = false;
default =
if from-nixos
then mod-args.osConfig.stylix.homeManagerIntegration.enable
else false;
};
};

View file

@ -1,8 +1,8 @@
{ palette-generator, base16, homeManagerModule }:
{ config, lib, ... }:
{ options, config, lib, ... }:
let
cfg = config.stylix.home-manager;
hm = config.stylix.homeManagerIntegration;
autoload = import ../autoload.nix { inherit lib; } "nixos";
in {
imports = [
@ -12,15 +12,33 @@ in {
(import ./palette.nix { inherit palette-generator base16; })
] ++ autoload;
options.stylix.home-manager = {
enable = lib.mkEnableOption "home-manager support";
useSystemTheme = lib.mkEnableOption "system theme in home-manager";
options.stylix.homeManagerIntegration = {
enable = lib.mkOption {
description = ''
Enable home-manager integration
This means that by default all the users will use the system
theme, and the stylix hm module will be included in all users
configurations.
'';
type = lib.types.bool;
default = options ? home-manager;
defaultText = "true if home-manager is imported";
};
disableImport = lib.mkOption {
description = ''
When the home-manager integration is enabled, do not automatically
imports stylix into the user configuration.
'';
type = lib.types.bool;
default = false;
};
};
config = lib.mkIf cfg.enable {
config = lib.mkIf (hm.enable && !hm.disableImport) {
home-manager.sharedModules = [
homeManagerModule
{ stylix.useSystemTheme = lib.mkOverride 99 cfg.useSystemTheme; }
];
};
}