nix/graphical/quick-services.nix
2026-03-09 14:06:12 +11:00

78 lines
1.7 KiB
Nix

{
config,
lib,
mainUser,
...
}:
let
inherit (lib) mkOption types mkIf;
inherit (types)
attrsOf
str
bool
submodule
;
in
scope "options.quick" {
services = mkOption {
type = attrsOf (
submodule (
{ ... }:
{
options = {
cmd = mkOption {
type = str;
};
restart = mkOption {
type = bool;
default = false;
};
};
}
)
);
default = { };
};
oneShots = mkOption {
type = attrsOf str;
default = { };
};
}
// scope "config.user.systemd" {
enable = true;
services =
builtins.mapAttrs (name: opts: {
environment.PATH = lib.mkForce "/run/current-system/sw/bin:/run/current-system/sw/sbin:/etc/profiles/per-user/${mainUser}/bin:/etc/profiles/per-user/${mainUser}/sbin";
unitConfig = {
Description = "${name}";
Requires = [
"graphical-session.target"
];
After = [
"graphical-session.target"
"niri.target"
];
PartOf = [ "graphical-session.target" ];
};
serviceConfig = {
ExecStart = opts.cmd;
Restart = mkIf (opts.restart) "always";
};
wantedBy = [ "graphical-session.target" ];
}) config.quick.services
// builtins.mapAttrs (name: cmd: {
unitConfig = {
Description = "${name}";
Requires = [ "graphical-session.target" ];
After = [
"graphical-session.target"
"niri.target"
];
};
serviceConfig = {
ExecStart = cmd;
Type = "oneshot";
};
wantedBy = [ "graphical-session.target" ];
}) config.quick.oneShots;
}