nosignal-shell/nix/hm-module.nix
BardMoon a17b76dea1
nix/hm: add systemd.target in home-manager (#532)
* nix: add systemd.target

* fix: format

* Update README.md

* Update hm-module.nix

cf2b1d8405/example-units/hyprpaper.service (L19)

* fix

* Update README.md
2025-09-01 18:06:02 +10:00

118 lines
3.2 KiB
Nix

self: {
config,
pkgs,
lib,
...
}: let
inherit (pkgs.stdenv.hostPlatform) system;
cli-default = self.inputs.caelestia-cli.packages.${system}.default;
shell-default = self.packages.${system}.with-cli;
cfg = config.programs.caelestia;
in {
options = with lib; {
programs.caelestia = {
enable = mkEnableOption "Enable Caelestia shell";
package = mkOption {
type = types.package;
default = shell-default;
description = "The package of Caelestia shell";
};
systemd = {
enable = mkOption {
type = types.bool;
default = true;
description = "Enable the systemd service for Caelestia shell";
};
target = mkOption {
type = types.str;
description = ''
The systemd target that will automatically start the Caelestia shell.
'';
default = "graphical-session.target";
};
};
settings = mkOption {
type = types.attrsOf types.anything;
default = {};
description = "Caelestia shell settings";
};
extraConfig = mkOption {
type = types.str;
default = "";
description = "Caelestia shell extra configs written to shell.json";
};
cli = {
enable = mkEnableOption "Enable Caelestia CLI";
package = mkOption {
type = types.package;
default = cli-default;
description = "The package of Caelestia CLI"; # Doesn't override the shell's CLI, only change from home.packages
};
settings = mkOption {
type = types.attrsOf types.anything;
default = {};
description = "Caelestia CLI settings";
};
extraConfig = mkOption {
type = types.str;
default = "{}";
description = "Caelestia CLI extra configs written to cli.json";
};
};
};
};
config = let
cli = cfg.cli.package or cli-default;
shell = cfg.package or shell-default;
in
lib.mkIf cfg.enable {
systemd.user.services.caelestia = lib.mkIf cfg.systemd.enable {
Unit = {
Description = "Caelestia Shell Service";
After = [cfg.systemd.target];
PartOf = [cfg.systemd.target];
X-Restart-Triggers = lib.mkIf (cfg.settings != {}) [
"${config.xdg.configFile."caelestia/shell.json".source}"
];
};
Service = {
Type = "exec";
ExecStart = "${shell}/bin/caelestia-shell";
Restart = "on-failure";
RestartSec = "5s";
TimeoutStopSec = "5s";
Environment = [
"QT_QPA_PLATFORM=wayland"
];
Slice = "session.slice";
};
Install = {
WantedBy = [cfg.systemd.target];
};
};
xdg.configFile = let
mkConfig = c:
lib.pipe (
if c.extraConfig != ""
then c.extraConfig
else "{}"
) [
builtins.fromJSON
(lib.recursiveUpdate c.settings)
builtins.toJSON
];
in {
"caelestia/shell.json".text = mkConfig cfg;
"caelestia/cli.json".text = mkConfig cfg.cli;
};
home.packages = [shell] ++ lib.optional cfg.cli.enable cli;
};
}