refactor module.nix

This commit is contained in:
Zynh Ludwig 2024-08-01 01:23:57 -07:00
parent 1f8104c456
commit c15afde777

View file

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