fetch-mutable-files: add the shell script for the service

This commit is contained in:
Gabriel Arazas 2023-03-15 19:31:49 +08:00
parent 99e69636fc
commit bed7a26c7f
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC

View File

@ -77,8 +77,22 @@ in
Type = "oneshot";
RemainAfterExit = true;
# TODO: Complete this
ExecStart = "";
ExecStart = let
curl = "${lib.getBin pkgs.curl}/bin/curl";
git = "${lib.getBin pkgs.curl}/bin/git";
fetchCmds = lib.mapAttrsToList (file: value:
let
inherit (value) type;
path = lib.escapeShellArg value.path;
url = lib.escapeURL value.url;
in ''
${lib.optionalString (type == "git") "[ -d ${path} ] || ${git} clone ${url} ${path}"}
${lib.optionalString (type == "fetch") "[ -d ${path} ] || ${curl} ${url} --output ${path}"}
'') cfg;
shellScript = pkgs.writeShellScript "fetch-mutable-files" ''
${lib.concatStringsSep "\n" fetchCmds}
'';
in builtins.toString shellScript;
};
Install.WantedBy = [ "default.target" ];