refactor module.nix

main
Zynh Ludwig 2024-08-01 01:23:57 -07:00
parent 1f8104c456
commit c15afde777
1 changed files with 17 additions and 17 deletions

View File

@ -3,12 +3,18 @@
let let
service = "repo-clone"; service = "repo-clone";
cfg = config.repo-clone; cfg = config.repo-clone;
inherit (lib) mkIf mkOption mkEnableOption types;
inherit (lib.strings) concatStringsSep;
inherit (lib.attrsets) mapAttrsToList;
inherit (pkgs) writeShellScriptBin writeText;
in in
{ {
options.${service} = { options.${service} = {
enable = lib.mkEnableOption "${service} service"; enable = mkEnableOption "${service} service";
repos = lib.mkOption { repos = mkOption {
type = import ./repo.nix { inherit lib; }; type = import ./repo.nix { inherit lib; };
description = '' description = ''
attrs of repos to clone attrs of repos to clone
@ -16,24 +22,22 @@ in
default = { }; default = { };
}; };
pkg = lib.mkOption { pkg = mkOption {
type = lib.types.package; type = types.package;
}; };
}; };
# /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 = lib.mkIf cfg.enable { config = mkIf cfg.enable {
systemd.user.services.${service} = { systemd.user.services.${service} = {
Unit = { Unit.Description = "${service} service";
Description = "${service} service";
};
Service = { Service = {
Type = "exec"; Type = "exec";
ExecStart = ExecStart =
let let
execName = service; execName = service;
script = pkgs.writeShellScriptBin execName '' script = writeShellScriptBin execName ''
echo "hello!" echo "hello!"
echo "${config.repo-clone.pkg}" echo "${config.repo-clone.pkg}"
''; '';
@ -41,15 +45,11 @@ in
"${script}/bin/${execName}"; "${script}/bin/${execName}";
RemainAfterExit = "yes"; RemainAfterExit = "yes";
}; };
Install = { Install.WantedBy = [ "multi-user.target" ];
WantedBy = [ "multi-user.target" ];
};
}; };
repo-clone.pkg = pkgs.writeText "${service}.conf" repo-clone.pkg = writeText "${service}.conf"
( (concatStringsSep "\n"
lib.strings.concatStringsSep "\n" (mapAttrsToList (target: settings: "${target} ${settings.url}") cfg.repos));
(lib.attrsets.mapAttrsToList (target: settings: "${target} ${settings.url}") cfg.repos)
);
}; };
} }