repo-clone/service.nix

43 lines
1.0 KiB
Nix

{ 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 ''
# Include hidden files when globbing later
shopt -s nullglob dotglob
set -xv
while IFS="" read -r p || [ -n "$p" ]
do
args=($p) # [0]: repo-url [1]: target-path
repo=''${args[0]}
target=''${args[1]}
if [ -d "$target" ]; then
if ${pkgs.findutils}/bin/find "$target" -maxdepth 0 -empty | read v; then
echo "~ No Files in $target ~"
else
echo "~ Found Files at $target ~"
fi
fi
done < "${config.repo-clone.pkg}"
'';
in
"${script}/bin/${execName}";
RemainAfterExit = "yes";
};
Install.WantedBy = [ "multi-user.target" ];
}