{ pkgs, lib, config, ... }: let cfg = config.rclone-mount; in { options = { rclone-mount = { enable = lib.mkEnableOption "rclone mount user services"; mounts = lib.mkOption { type = lib.types.attrs; default = { }; example = { "minio" = "/home/${config.home.username}/minio/"; }; description = "List of mount configurations"; }; configPath = lib.mkOption { type = lib.types.str; default = "~/.config/rclone/rclone.conf"; description = "Path to the rclone configuration"; }; }; }; config = { systemd.user.services = lib.attrsets.mapAttrs' (name: path: { name = "rclone-${name}"; value = { Unit = { Description = "rclone mount for ${name}"; After = [ "default.target" ]; PartOf = [ "default.target" ]; }; Install.WantedBy = [ "default.target" ]; Service = { Type = "simple"; Environment = [ "PATH=${ lib.makeBinPath [ pkgs.rclone pkgs.coreutils pkgs.fuse ]}:/run/wrappers/bin/:$PATH" ]; ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p ${path}"; ExecStart = "${pkgs.rclone}/bin/rclone --config '${cfg.configPath}' mount ${name}:/ ${path} -vv --allow-other --vfs-cache-mode=writes --s3-upload-concurrency 32 --s3-chunk-size 128000"; Restart = "on-failure"; RestartSec = "30s"; }; }; }) (if cfg.enable then cfg.mounts else { }); }; }