63 lines
1.6 KiB
Nix
63 lines
1.6 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
with lib;
|
|
let
|
|
cfg = config.services.rclone-serve;
|
|
|
|
makeNameSafe = name: builtins.replaceStrings [ "/" ] [ "-" ] name;
|
|
|
|
daemonService = serve_config: {
|
|
enable = true;
|
|
after = [ "network.target" ];
|
|
wants = [ "network.target" ]
|
|
++ (if serve_config.wants != null then serve_config.wants else [ ]);
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig = {
|
|
Type = "simple";
|
|
Restart = "on-failure";
|
|
RestartSec = "5s";
|
|
|
|
User =
|
|
if serve_config.user != null then "${serve_config.user}" else "root";
|
|
|
|
ExecStart =
|
|
"${pkgs.rclone}/bin/rclone serve ${serve_config.type} ${serve_config.remote} ${
|
|
lib.concatStringsSep " " serve_config.extraArgs
|
|
}";
|
|
};
|
|
};
|
|
in {
|
|
options = {
|
|
services.rclone-serve = {
|
|
enable = mkOption {
|
|
type = types.bool;
|
|
default = false;
|
|
};
|
|
|
|
remotes = mkOption {
|
|
type = types.listOf (types.submodule {
|
|
options = {
|
|
remote = mkOption { type = types.str; };
|
|
type = mkOption { type = types.str; };
|
|
user = mkOption { type = types.str; };
|
|
wants = mkOption { type = types.listOf types.str; };
|
|
|
|
extraArgs = mkOption { type = types.listOf types.str; };
|
|
};
|
|
});
|
|
default = [ ];
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkMerge [
|
|
(mkIf (cfg.enable && cfg.remotes != [ ]) {
|
|
systemd.services = listToAttrs (map (remote: {
|
|
name = "rclone-serve-${makeNameSafe remote.remote}-${
|
|
makeNameSafe remote.type
|
|
}";
|
|
value = daemonService remote;
|
|
}) cfg.remotes);
|
|
})
|
|
];
|
|
}
|