96 lines
2.3 KiB
Nix
96 lines
2.3 KiB
Nix
self: {
|
|
lib,
|
|
config,
|
|
pkgs,
|
|
...
|
|
}: let
|
|
inherit (lib.options) mkEnableOption mkOption;
|
|
inherit (lib.types) str path port int;
|
|
inherit (lib.modules) mkIf;
|
|
|
|
cfg = config.services.tinyupload;
|
|
in {
|
|
options.services.tinyupload = {
|
|
enable = mkEnableOption "Enable tinyupload.";
|
|
|
|
address = mkOption {
|
|
type = str;
|
|
default = "127.0.0.1";
|
|
description = "Address on which tinyupload will listen on";
|
|
};
|
|
|
|
port = mkOption {
|
|
type = port;
|
|
default = 8080;
|
|
description = "Port on which the tinyupload service will listen";
|
|
};
|
|
|
|
uploadLimit = mkOption {
|
|
type = int;
|
|
default = 100;
|
|
description = "Upload limit for tinyupload in MB";
|
|
};
|
|
|
|
title = mkOption {
|
|
type = str;
|
|
default = "tinyupload";
|
|
description = "Title for the frontend of tinyupload";
|
|
};
|
|
|
|
dataDir = mkOption {
|
|
type = path;
|
|
default = "/var/lib/tinyupload";
|
|
description = "Directory to store uploaded files and database";
|
|
};
|
|
|
|
user = mkOption {
|
|
type = str;
|
|
default = "tinyupload";
|
|
description = "User account under which the service will run";
|
|
};
|
|
|
|
group = mkOption {
|
|
type = str;
|
|
default = "tinyupload";
|
|
description = "Group under which the service will run";
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
users.users.${cfg.user} = {
|
|
isSystemUser = true;
|
|
group = cfg.group;
|
|
home = cfg.dataDir;
|
|
createHome = true;
|
|
description = "tinyupload service user";
|
|
};
|
|
|
|
users.groups.${cfg.group} = {};
|
|
|
|
environment.systemPackages = [self.packages.${pkgs.system}.tinyupload];
|
|
|
|
systemd.services.tinyupload = {
|
|
description = "tinyupload service";
|
|
wantedBy = ["multi-user.target"];
|
|
after = ["network.target"];
|
|
|
|
serviceConfig = {
|
|
RestartSec = 5;
|
|
User = cfg.user;
|
|
Group = cfg.group;
|
|
WorkingDirectory = cfg.dataDir;
|
|
Restart = "on-failure";
|
|
ExecStart = "${(pkgs.writeShellApplication {
|
|
name = "start-tinyupload";
|
|
text = ''
|
|
${self.packages.${pkgs.system}.tinyupload}/bin/tinyupload \
|
|
-u ${toString cfg.uploadLimit} \
|
|
-a "${cfg.address}:${toString cfg.port}" \
|
|
-t "${cfg.title}" \
|
|
serve
|
|
'';
|
|
})}/bin/start-tinyupload";
|
|
};
|
|
};
|
|
};
|
|
}
|