11.stylix/stylix/home-manager-integration.nix
Konrad Malik c27bc6e9f9
stylix/home-manager-integration: fix evaluation on darwin (#1973)
Closes: https://github.com/nix-community/stylix/issues/1981
Link: https://github.com/nix-community/stylix/pull/1973

Reviewed-by: 0xda157 <da157@voidq.com>
Approved-by: https://github.com/pastadudes
Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
2025-11-20 15:43:32 +01:00

234 lines
4.7 KiB
Nix

{
lib,
config,
options,
...
}:
let
copyModules =
map
(
{
path,
condition ? lib.const true,
}:
{ config, osConfig, ... }:
lib.optionalAttrs (lib.hasAttrByPath path osConfig) (
lib.mkIf (condition config) (
lib.setAttrByPath path (lib.mkDefault (lib.getAttrFromPath path osConfig))
)
)
)
[
# keep-sorted start block=yes
{
path = [
"stylix"
"autoEnable"
];
}
{
path = [
"stylix"
"base16Scheme"
];
condition = homeConfig: config.stylix.image == homeConfig.stylix.image;
}
{
path = [
"stylix"
"cursor"
];
}
{
path = [
"stylix"
"enable"
];
}
{
path = [
"stylix"
"fonts"
"emoji"
];
}
{
path = [
"stylix"
"fonts"
"monospace"
];
}
{
path = [
"stylix"
"fonts"
"sansSerif"
];
}
{
path = [
"stylix"
"fonts"
"serif"
];
}
{
path = [
"stylix"
"fonts"
"sizes"
"applications"
];
}
{
path = [
"stylix"
"fonts"
"sizes"
"desktop"
];
}
{
path = [
"stylix"
"fonts"
"sizes"
"popups"
];
}
{
path = [
"stylix"
"fonts"
"sizes"
"terminal"
];
}
{
path = [
"stylix"
"icons"
];
}
{
path = [
"stylix"
"image"
];
}
{
path = [
"stylix"
"imageScalingMode"
];
}
{
path = [
"stylix"
"opacity"
"applications"
];
}
{
path = [
"stylix"
"opacity"
"desktop"
];
}
{
path = [
"stylix"
"opacity"
"popups"
];
}
{
path = [
"stylix"
"opacity"
"terminal"
];
}
{
path = [
"stylix"
"override"
];
condition =
homeConfig: config.stylix.base16Scheme == homeConfig.stylix.base16Scheme;
}
{
path = [
"stylix"
"polarity"
];
}
{
path = [
"stylix"
"targets"
"qt"
"platform"
];
}
# keep-sorted end
];
in
{
options.stylix.homeManagerIntegration = {
followSystem = lib.mkOption {
description = ''
When this option is `true`, Home Manager configurations will follow
the NixOS configuration by default, rather than using the standard
default settings.
This only applies to Home Manager configurations managed by
[`stylix.homeManagerIntegration.autoImport`](#stylixhomemanagerintegrationautoimport).
'';
type = lib.types.bool;
default = true;
example = false;
};
autoImport = lib.mkOption {
description = ''
Whether to import Stylix automatically for every Home Manager user.
This only works if you are using `home-manager.users.«name»` within
your NixOS configuration, rather than running Home Manager independently.
'';
type = lib.types.bool;
default = true;
example = false;
};
module = lib.mkOption {
description = ''
The Home Manager module to be imported.
'';
internal = true;
readOnly = true;
};
};
config = lib.mkIf config.stylix.enable (
lib.optionalAttrs (options ? home-manager) (
lib.mkMerge [
(lib.mkIf config.stylix.homeManagerIntegration.autoImport {
home-manager.sharedModules = [
config.stylix.homeManagerIntegration.module
]
++ lib.optionals config.stylix.homeManagerIntegration.followSystem copyModules;
})
(lib.mkIf config.home-manager.useGlobalPkgs {
home-manager.sharedModules = lib.singleton {
config.stylix.overlays.enable = false;
};
})
]
)
);
}