11.stylix/modules/swaylock/hm.nix
NAHO dfc859f54d
treewide: optionalize mkTarget's humanName and name arguments
Optionalize mkTarget's 'humanName' and 'name' arguments by inferring
'humanName' from the 'name' attribute in the /modules/<MODULE>/meta.nix
file, and 'name' from the /modules/<NAME>/ directory name.

Inferring the 'humanName' and 'name' arguments ensures consistency and
reduces boilerplate.

The 'humanName' and 'name' arguments are optionalized instead of removed
because complex modules generating target derivations need to
distinguish between them.

Closes: https://github.com/nix-community/stylix/issues/1661
2025-12-10 14:48:37 +01:00

98 lines
2.6 KiB
Nix

{
mkTarget,
pkgs,
config,
lib,
...
}:
mkTarget {
# When the state version is older than 23.05, Swaylock enables itself
# automatically if `settings != {}` [1]. Therefore, Swaylock theming
# shouldn't be enabled by default for such state versions, to avoid
# inadvertently installing Swaylock when it's not desired.
#
# Adding `&& config.programs.swaylock.enable` below may lead to infinite
# recursion, due to the above.
#
# [1]: https://github.com/nix-community/home-manager/blob/5cfbf5cc37a3bd1da07ae84eea1b828909c4456b/modules/programs/swaylock.nix#L12-L17
autoEnable =
lib.versionAtLeast config.home.stateVersion "23.05"
&& pkgs.stdenv.hostPlatform.isLinux;
autoEnableExpr = ''
lib.versionAtLeast config.home.stateVersion "23.05" && pkgs.stdenv.hostPlatform.isLinux
'';
options.useWallpaper = config.lib.stylix.mkEnableWallpaper "Swaylock" true;
config = [
(
{ colors }:
{
programs.swaylock.settings =
with colors;
let
inside = base00-hex;
outside = base00-hex;
ring = base01-hex;
text = base05-hex;
positive = base0B-hex;
negative = base08-hex;
in
{
color = outside;
inside-color = inside;
inside-clear-color = inside;
inside-caps-lock-color = inside;
inside-ver-color = inside;
inside-wrong-color = inside;
key-hl-color = positive;
layout-bg-color = inside;
layout-border-color = ring;
layout-text-color = text;
line-uses-inside = true;
ring-color = ring;
ring-clear-color = negative;
ring-caps-lock-color = ring;
ring-ver-color = positive;
ring-wrong-color = negative;
separator-color = "00000000";
text-color = text;
text-clear-color = text;
text-caps-lock-color = text;
text-ver-color = text;
text-wrong-color = text;
};
}
)
(
{ cfg, image }:
{
programs.swaylock.settings.image = lib.mkIf cfg.useWallpaper image;
}
)
(
{ imageScalingMode }:
{
programs.swaylock.settings.scaling = imageScalingMode;
}
)
];
imports = [
(lib.mkRenamedOptionModuleWith {
from = [
"stylix"
"targets"
"swaylock"
"useImage"
];
sinceRelease = 2505;
to = [
"stylix"
"targets"
"swaylock"
"useWallpaper"
];
})
];
}