infrastructure/config/modules/home/swaylock.nix
2021-08-30 19:36:48 +01:00

44 lines
1.1 KiB
Nix

{ config, lib, pkgs, ... }: with lib;
let cfg = config.programs.swaylock; in
{
options.programs.swaylock = {
enable = mkEnableOption "locker integration";
package = mkOption {
type = types.package;
default = pkgs.swaylock-effects;
};
wrapped = mkOption {
type = types.package;
};
script = mkOption {
type = types.path;
default = "${cfg.wrapped}/bin/swaylock";
};
colors = mkOption {
type = types.attrsOf types.str;
default = { };
};
args = mkOption {
type = with types; attrsOf (oneOf [ str bool int float ]);
default = { };
};
};
config = mkIf cfg.enable {
programs.swaylock = let
argList = concatLists (mapAttrsToList (arg: value:
if value == true then
singleton "--${toString arg}"
else [
"--${arg}"
(toString value)
]) cfg.args);
argStr = escapeShellArgs argList;
in {
args = mapAttrs' (arg: color: nameValuePair ("${arg}-color") (removePrefix "#" color)) cfg.colors;
wrapped = pkgs.writeShellScriptBin "swaylock" ''
${cfg.package}/bin/swaylock ${argStr} $@
'';
};
};
}