{ tgcMaintainers, ... }: { config, pkgs, lib, ... }: let inherit (lib) types; cfg = config.tgc.programs.gtklock; configFormat = pkgs.formats.ini { listToValue = builtins.concatStringsSep ";"; }; configFile = configFormat.generate "gtklock-config.ini" cfg.settings; in { meta.maintainers = [ tgcMaintainers.zaphyra ]; options.tgc.programs.gtklock = { enable = lib.mkEnableOption "gtklock, a GTK-based lockscreen for Wayland"; package = lib.mkPackageOption pkgs "gtklock" { }; systemd.enable = lib.mkEnableOption "Enable systemd user service (can be used with e.g. systemd-lock-handler)"; settings = lib.mkOption { type = configFormat.type; example = lib.literalExpression '' { main = { idle-hide = true; idle-timeout = 10; }; }''; description = '' Configuration for gtklock. See [`gtklock(1)`](https://github.com/jovanlanik/gtklock/blob/master/man/gtklock.1.scd) man page for details. ''; }; style = lib.mkOption { type = with types; nullOr str; default = null; description = '' CSS Stylesheet for gtklock. See [gtklock's wiki](https://github.com/jovanlanik/gtklock/wiki#Styling) for details. ''; }; modules = lib.mkOption { type = with types; listOf package; default = [ ]; example = lib.literalExpression '' with pkgs; [ gtklock-playerctl-module gtklock-powerbar-module gtklock-userinfo-module ]''; description = "gtklock modules to load."; }; }; config = lib.mkIf cfg.enable { tgc.programs.gtklock.settings.main = { style = lib.mkIf (cfg.style != null) "${pkgs.writeText "style.css" cfg.style}"; modules = lib.mkIf (cfg.modules != [ ]) ( map (pkg: "${pkg}/lib/gtklock/${lib.removePrefix "gtklock-" pkg.pname}.so") cfg.modules ); }; xdg.configFile."gtklock/config.ini" = lib.mkIf (cfg.settings != { }) { source = configFile; }; home.packages = [ cfg.package ]; systemd.user.services.gtklock = lib.mkIf cfg.systemd.enable { Unit = { Description = "GTK-based lockscreen for Wayland"; Documentation = "https://github.com/jovanlanik/gtklock"; OnSuccess = [ "unlock.target" ]; PartOf = [ "lock.target" ]; After = [ "lock.target" ]; }; Service = { ExecStart = lib.getExe cfg.package; Restart = "on-failure"; RestartSec = 0; }; Install.WantedBy = [ "lock.target" ]; }; }; }