From 8c55205c66816e9f2f6f5a5e44a772d5ba62c157 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Mon, 13 May 2024 01:20:01 +0200 Subject: [PATCH] Add a module for creating `rclone` services --- lib/modules/rclone.nix | 54 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 lib/modules/rclone.nix diff --git a/lib/modules/rclone.nix b/lib/modules/rclone.nix new file mode 100644 index 0000000..46886b3 --- /dev/null +++ b/lib/modules/rclone.nix @@ -0,0 +1,54 @@ +{ config, lib, pkgs, ... }: { + options = { + programs.rclone = { + enable = lib.mkEnableOption "rclone"; + }; + }; + + config = + let + cfg = config.programs.rclone; + in { + home.packages = lib.optional cfg.enable pkgs.rclone; + + systemd.user = lib.optionalAttrs cfg.enable { + enable = true; + + services.rclone = { + Unit = { + Description = "rclone Starter"; + Documentation = "man:rclone(1)"; + }; + + Service = { + Type = "simple"; + + ExecStartPre = + let + scriptName = "rclone-pre"; + script = pkgs.writeShellScriptBin scriptName '' + sleep 10 + ''; + in + "${script}/bin/${scriptName}"; + + ExecStart = + let + scriptName = "rclone"; + script = pkgs.writeShellScriptBin scriptName '' + systemctl --user start rclone.target + ''; + in + "${script}/bin/${scriptName}"; + }; + }; + + targets.rclone = { + Unit = { + Description = "rclone Mounts"; + Documentation = "man:rclone(1)"; + }; + }; + }; + }; +}