diff --git a/home/modules/console/utility/default.nix b/home/modules/console/utility/default.nix index b878df2..3540a60 100644 --- a/home/modules/console/utility/default.nix +++ b/home/modules/console/utility/default.nix @@ -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"; + }; }; } diff --git a/home/modules/console/utility/transientServices/default.nix b/home/modules/console/utility/transientServices/default.nix new file mode 100644 index 0000000..0a6fa65 --- /dev/null +++ b/home/modules/console/utility/transientServices/default.nix @@ -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]; + }; + }; +} diff --git a/home/profile/base/default.nix b/home/profile/base/default.nix index bf1092b..a0f7db3 100644 --- a/home/profile/base/default.nix +++ b/home/profile/base/default.nix @@ -74,6 +74,7 @@ in nixIndex.enable = true; git.enable = true; tools.enable = true; + transientServices.enable = true; }; }; };