swaylock: add enable and package option
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
parent
75f4f362e1
commit
2df3d5d39c
|
@ -1,32 +1,54 @@
|
||||||
{ config, lib, ... }:
|
{ pkgs, config, lib, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
let cfg = config.programs.swaylock;
|
let cfg = config.programs.swaylock;
|
||||||
in {
|
in {
|
||||||
meta.maintainers = [ lib.hm.maintainers.rcerc ];
|
meta.maintainers = [ hm.maintainers.rcerc ];
|
||||||
|
|
||||||
options.programs.swaylock.settings = lib.mkOption {
|
options.programs.swaylock = {
|
||||||
type = with lib.types; attrsOf (oneOf [ bool float int str ]);
|
enable = mkOption {
|
||||||
default = { };
|
type = lib.types.bool;
|
||||||
description = ''
|
default = versionOlder config.home.stateVersion "23.05"
|
||||||
Default arguments to <command>swaylock</command>. An empty set
|
&& (cfg.settings != { });
|
||||||
disables configuration generation.
|
defaultText = literalExpression ''
|
||||||
'';
|
true if state version < 23.05 and settings ≠ { },
|
||||||
example = {
|
false otherwise
|
||||||
color = "808080";
|
'';
|
||||||
font-size = 24;
|
example = true;
|
||||||
indicator-idle-visible = false;
|
description = "Whether to enable swaylock.";
|
||||||
indicator-radius = 100;
|
};
|
||||||
line-color = "ffffff";
|
|
||||||
show-failed-attempts = true;
|
package = mkPackageOption pkgs "swaylock" { };
|
||||||
|
|
||||||
|
settings = mkOption {
|
||||||
|
type = with types; attrsOf (oneOf [ bool float int str ]);
|
||||||
|
default = { };
|
||||||
|
description = ''
|
||||||
|
Default arguments to <command>swaylock</command>. An empty set
|
||||||
|
disables configuration generation.
|
||||||
|
'';
|
||||||
|
example = {
|
||||||
|
color = "808080";
|
||||||
|
font-size = 24;
|
||||||
|
indicator-idle-visible = false;
|
||||||
|
indicator-radius = 100;
|
||||||
|
line-color = "ffffff";
|
||||||
|
show-failed-attempts = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config.xdg.configFile."swaylock/config" = lib.mkIf (cfg.settings != { }) {
|
config = mkIf cfg.enable {
|
||||||
text = lib.concatStrings (lib.mapAttrsToList (n: v:
|
home.packages = [ cfg.package ];
|
||||||
if v == false then
|
|
||||||
""
|
xdg.configFile."swaylock/config" = mkIf (cfg.settings != { }) {
|
||||||
else
|
text = concatStrings (mapAttrsToList (n: v:
|
||||||
(if v == true then n else n + "=" + builtins.toString v) + "\n")
|
if v == false then
|
||||||
cfg.settings);
|
""
|
||||||
|
else
|
||||||
|
(if v == true then n else n + "=" + builtins.toString v) + "\n")
|
||||||
|
cfg.settings);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
{
|
{
|
||||||
swaylock-disabled = import ./disabled.nix;
|
swaylock-disabled = import ./disabled.nix;
|
||||||
swaylock-settings = import ./settings.nix;
|
swaylock-settings = import ./settings.nix;
|
||||||
|
swaylock-enabled = import ./enabled.nix;
|
||||||
|
swaylock-legacy = import ./legacy.nix;
|
||||||
}
|
}
|
||||||
|
|
10
tests/modules/programs/swaylock/enabled.nix
Normal file
10
tests/modules/programs/swaylock/enabled.nix
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{ config, ... }: {
|
||||||
|
programs.swaylock = {
|
||||||
|
enable = true;
|
||||||
|
package = config.lib.test.mkStubPackage { };
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertPathNotExists home-files/.config/swaylock/config
|
||||||
|
'';
|
||||||
|
}
|
19
tests/modules/programs/swaylock/legacy.nix
Normal file
19
tests/modules/programs/swaylock/legacy.nix
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
home.stateVersion = "20.09";
|
||||||
|
programs.swaylock = {
|
||||||
|
settings = {
|
||||||
|
color = "808080";
|
||||||
|
font-size = 24;
|
||||||
|
indicator-idle-visible = false; # Test that this does nothing
|
||||||
|
indicator-radius = 100;
|
||||||
|
line-color = "ffffff";
|
||||||
|
show-failed-attempts = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script = let homeConfig = "home-files/.config/swaylock/config";
|
||||||
|
in ''
|
||||||
|
assertFileExists ${homeConfig}
|
||||||
|
assertFileContent ${homeConfig} ${./config}
|
||||||
|
'';
|
||||||
|
}
|
|
@ -1,11 +1,14 @@
|
||||||
{ ... }: {
|
{
|
||||||
programs.swaylock.settings = {
|
programs.swaylock = {
|
||||||
color = "808080";
|
enable = true;
|
||||||
font-size = 24;
|
settings = {
|
||||||
indicator-idle-visible = false; # Test that this does nothing
|
color = "808080";
|
||||||
indicator-radius = 100;
|
font-size = 24;
|
||||||
line-color = "ffffff";
|
indicator-idle-visible = false; # Test that this does nothing
|
||||||
show-failed-attempts = true;
|
indicator-radius = 100;
|
||||||
|
line-color = "ffffff";
|
||||||
|
show-failed-attempts = true;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
nmt.script = let homeConfig = "home-files/.config/swaylock/config";
|
nmt.script = let homeConfig = "home-files/.config/swaylock/config";
|
||||||
|
|
Loading…
Reference in a new issue