extract service.nix

This commit is contained in:
Zynh Ludwig 2024-08-01 01:48:41 -07:00
parent c15afde777
commit e8c6f48bec
2 changed files with 28 additions and 18 deletions

View file

@ -8,7 +8,7 @@ let
inherit (lib.strings) concatStringsSep; inherit (lib.strings) concatStringsSep;
inherit (lib.attrsets) mapAttrsToList; inherit (lib.attrsets) mapAttrsToList;
inherit (pkgs) writeShellScriptBin writeText; inherit (pkgs) writeText;
in in
{ {
options.${service} = { options.${service} = {
@ -30,23 +30,7 @@ in
# /nix/store/pxd7wc8icz577hpl6pmz02b74nhbrj6h-unit-home-manager-ravenshade.service/home-manager-ravenshade.service # /nix/store/pxd7wc8icz577hpl6pmz02b74nhbrj6h-unit-home-manager-ravenshade.service/home-manager-ravenshade.service
config = mkIf cfg.enable { config = mkIf cfg.enable {
systemd.user.services.${service} = { systemd.user.services.${service} = import ./service.nix { inherit service pkgs config; };
Unit.Description = "${service} service";
Service = {
Type = "exec";
ExecStart =
let
execName = service;
script = writeShellScriptBin execName ''
echo "hello!"
echo "${config.repo-clone.pkg}"
'';
in
"${script}/bin/${execName}";
RemainAfterExit = "yes";
};
Install.WantedBy = [ "multi-user.target" ];
};
repo-clone.pkg = writeText "${service}.conf" repo-clone.pkg = writeText "${service}.conf"
(concatStringsSep "\n" (concatStringsSep "\n"

26
service.nix Normal file
View file

@ -0,0 +1,26 @@
{ config, service, pkgs }:
let
inherit (pkgs)
writeShellScriptBin;
in
{
Unit = {
Description = "${service} service";
X-Restart-Triggers = [ "${config.repo-clone.pkg}" ];
};
Service = {
Type = "exec";
ExecStart =
let
execName = service;
script = writeShellScriptBin execName ''
echo "hello!"
echo "${config.repo-clone.pkg}"
'';
in
"${script}/bin/${execName}";
RemainAfterExit = "yes";
};
Install.WantedBy = [ "multi-user.target" ];
}