2018-07-20 20:56:59 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
2016-04-20 07:32:11 +00:00
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.zerobin;
|
|
|
|
|
|
|
|
zerobin_config = pkgs.writeText "zerobin-config.py" ''
|
|
|
|
PASTE_FILES_ROOT = "${cfg.dataDir}"
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.zerobin = {
|
|
|
|
enable = mkEnableOption "0bin";
|
|
|
|
|
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/lib/zerobin";
|
|
|
|
description = ''
|
|
|
|
Path to the 0bin data directory
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "zerobin";
|
|
|
|
description = ''
|
|
|
|
The user 0bin should run as
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "zerobin";
|
|
|
|
description = ''
|
|
|
|
The group 0bin should run as
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
listenPort = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 8000;
|
|
|
|
example = 1357;
|
|
|
|
description = ''
|
|
|
|
The port zerobin should listen on
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
listenAddress = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
|
|
|
example = "127.0.0.1";
|
|
|
|
description = ''
|
|
|
|
The address zerobin should listen to
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = ''
|
|
|
|
MENU = (
|
|
|
|
('Home', '/'),
|
|
|
|
)
|
|
|
|
COMPRESSED_STATIC_FILE = True
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Extra configuration to be appended to the 0bin config file
|
|
|
|
(see https://0bin.readthedocs.org/en/latest/en/options.html)
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg.enable) {
|
2019-08-13 21:52:01 +00:00
|
|
|
users.users.${cfg.user} =
|
2023-06-25 10:25:42 +00:00
|
|
|
optionalAttrs (cfg.user == "zerobin") {
|
2016-04-20 07:32:11 +00:00
|
|
|
isSystemUser = true;
|
|
|
|
group = cfg.group;
|
|
|
|
home = cfg.dataDir;
|
|
|
|
createHome = true;
|
2023-06-25 10:25:42 +00:00
|
|
|
};
|
2019-08-13 21:52:01 +00:00
|
|
|
users.groups.${cfg.group} = {};
|
2016-04-20 07:32:11 +00:00
|
|
|
|
|
|
|
systemd.services.zerobin = {
|
|
|
|
enable = true;
|
2016-09-10 18:19:35 +00:00
|
|
|
after = [ "network.target" ];
|
2016-04-20 07:32:11 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2020-09-27 07:33:46 +00:00
|
|
|
serviceConfig.ExecStart = "${pkgs.zerobin}/bin/zerobin ${cfg.listenAddress} ${toString cfg.listenPort} false ${cfg.user} ${cfg.group} ${zerobin_config}";
|
2016-04-20 07:32:11 +00:00
|
|
|
serviceConfig.PrivateTmp="yes";
|
|
|
|
serviceConfig.User = cfg.user;
|
|
|
|
serviceConfig.Group = cfg.group;
|
|
|
|
preStart = ''
|
2016-09-08 20:19:43 +00:00
|
|
|
mkdir -p ${cfg.dataDir}
|
|
|
|
chown ${cfg.user} ${cfg.dataDir}
|
2016-04-20 07:32:11 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|