sherlock: add systemd.enable option (#7678)

Add the ability to run sherlock as a daemon through systemd.
This commit is contained in:
Tim 2025-08-16 05:12:17 +02:00 committed by GitHub
parent 11626a4383
commit 2a749f4790
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -52,6 +52,8 @@ in
};
};
systemd.enable = lib.mkEnableOption "sherlock as a daemon";
aliases = mkOption {
inherit (jsonFormat) type;
default = { };
@ -125,18 +127,22 @@ in
xdg.configFile = {
"sherlock/config.toml" = mkIf (cfg.settings != { }) {
onChange = mkIf cfg.systemd.enable "${lib.getExe' pkgs.systemd "systemctl"} --user restart sherlock.service";
source = tomlFormat.generate "sherlock-config.toml" cfg.settings;
};
"sherlock/sherlock_alias.json" = mkIf (cfg.aliases != { }) {
onChange = mkIf cfg.systemd.enable "${lib.getExe' pkgs.systemd "systemctl"} --user restart sherlock.service";
source = jsonFormat.generate "sherlock_alias.json" cfg.aliases;
};
"sherlock/fallback.json" = mkIf (cfg.launchers != [ ]) {
onChange = mkIf cfg.systemd.enable "${lib.getExe' pkgs.systemd "systemctl"} --user restart sherlock.service";
source = jsonFormat.generate "sherlock-fallback.json" cfg.launchers;
};
"sherlock/sherlockignore" = mkIf (cfg.ignore != "") {
onChange = mkIf cfg.systemd.enable "${lib.getExe' pkgs.systemd "systemctl"} --user restart sherlock.service";
text = cfg.ignore;
};
@ -144,5 +150,15 @@ in
text = cfg.style;
};
};
systemd.user.services.sherlock = lib.mkIf cfg.systemd.enable {
Unit.Description = "Sherlock - App Launcher";
Install.WantedBy = [ "graphical-session.target" ];
Service = {
Environment = [ "DISPLAY=:0" ];
ExecStart = "${lib.getExe cfg.package} --daemonize";
Restart = "on-failure";
};
};
};
}