feat(transientServices): add transient services module, credit to github:NotAShelf

This commit is contained in:
ooks-io 2024-03-04 18:46:58 +13:00
parent 7d3d715408
commit 2d83b0f10d
3 changed files with 38 additions and 0 deletions

View file

@ -5,6 +5,7 @@
./git
./tools
./ssh
./transientServices
];
options.homeModules.console.utility = {
@ -20,5 +21,8 @@
tools = {
enable = lib.mkEnableOption "Enable various console tools";
};
transientServices = {
enable = lib.mkEnableOption "Enable various console transientServices";
};
};
}

View file

@ -0,0 +1,33 @@
# taken from github:NotAShelf/fufexan
{ pkgs, config, lib, ... }:
let
cfg = config.homeModules.console.utility.transientServices;
apply-hm-env = pkgs.writeShellScript "apply-hm-env" ''
${lib.optionalString (config.home.sessionPath != []) ''
export PATH=${builtins.concatStringsSep ":" config.home.sessionPath}:$PATH
''}
${builtins.concatStringsSep "\n" (lib.mapAttrsToList (k: v: ''
export ${k}=${toString v}
'')
config.home.sessionVariables)}
${config.home.sessionVariablesExtra}
exec "$@"
'';
# runs processes as systemd transient services
run-as-service = pkgs.writeShellScriptBin "run-as-service" ''
exec ${pkgs.systemd}/bin/systemd-run \
--slice=app-manual.slice \
--property=ExitType=cgroup \
--user \
--wait \
bash -lc "exec ${apply-hm-env} $@"
'';
in
{
config = lib.mkIf cfg.enable {
home = {
packages = [run-as-service];
};
};
}

View file

@ -74,6 +74,7 @@ in
nixIndex.enable = true;
git.enable = true;
tools.enable = true;
transientServices.enable = true;
};
};
};