repo-clone/service.nix

49 lines
1.3 KiB
Nix
Raw Normal View History

2024-08-01 08:48:41 +00:00
{ 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 ''
2024-08-01 10:50:08 +00:00
clone_repo() {
2024-08-01 10:53:19 +00:00
${pkgs.git}/bin/git clone "$1" "$2"
2024-08-01 10:50:08 +00:00
}
2024-08-01 09:50:57 +00:00
2024-08-01 09:10:43 +00:00
while IFS="" read -r p || [ -n "$p" ]
do
2024-08-01 09:37:36 +00:00
args=($p) # [0]: repo-url [1]: target-path
repo=''${args[0]}
target=''${args[1]}
2024-08-01 10:21:36 +00:00
if [ -d "$target" ]; then
2024-08-01 10:43:17 +00:00
if ${pkgs.findutils}/bin/find "$target" -maxdepth 0 -empty | read v; then
2024-08-01 10:52:17 +00:00
echo "Cloning Repo: $repo to $target"
2024-08-01 10:50:08 +00:00
clone_repo "$repo" "$target"
2024-08-01 10:38:18 +00:00
else
2024-08-01 10:50:08 +00:00
echo "Files already found: $target"
2024-08-01 09:37:36 +00:00
fi
2024-08-01 10:50:08 +00:00
else
2024-08-01 10:52:17 +00:00
echo "Making Directory: $target"
2024-08-01 10:51:02 +00:00
${pkgs.coreutils}/bin/mkdir -p "$target"
2024-08-01 10:52:17 +00:00
echo "Cloning Repo: $repo to $target"
2024-08-01 10:50:08 +00:00
clone_repo "$repo" "$target"
2024-08-01 09:37:36 +00:00
fi
2024-08-01 09:10:43 +00:00
done < "${config.repo-clone.pkg}"
2024-08-01 08:48:41 +00:00
'';
in
"${script}/bin/${execName}";
RemainAfterExit = "yes";
};
Install.WantedBy = [ "multi-user.target" ];
}