repo-clone/module.nix

56 lines
1.4 KiB
Nix

{ lib, config, pkgs, ... }:
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 = mkEnableOption "${service} service";
repos = mkOption {
type = import ./repo.nix { inherit lib; };
description = ''
attrs of repos to clone
'';
default = { };
};
pkg = mkOption {
type = types.package;
};
};
# /nix/store/pxd7wc8icz577hpl6pmz02b74nhbrj6h-unit-home-manager-ravenshade.service/home-manager-ravenshade.service
config = mkIf cfg.enable {
systemd.user.services.${service} = {
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"
(concatStringsSep "\n"
(mapAttrsToList (target: settings: "${target} ${settings.url}") cfg.repos));
};
}