1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7with lib;
8let
9 cfg = config.services.zerobin;
10
11 zerobin_config = pkgs.writeText "zerobin-config.py" ''
12 PASTE_FILES_ROOT = "${cfg.dataDir}"
13 ${cfg.extraConfig}
14 '';
15
16in
17{
18 options = {
19 services.zerobin = {
20 enable = mkEnableOption "0bin";
21
22 dataDir = mkOption {
23 type = types.str;
24 default = "/var/lib/zerobin";
25 description = ''
26 Path to the 0bin data directory
27 '';
28 };
29
30 user = mkOption {
31 type = types.str;
32 default = "zerobin";
33 description = ''
34 The user 0bin should run as
35 '';
36 };
37
38 group = mkOption {
39 type = types.str;
40 default = "zerobin";
41 description = ''
42 The group 0bin should run as
43 '';
44 };
45
46 listenPort = mkOption {
47 type = types.int;
48 default = 8000;
49 example = 1357;
50 description = ''
51 The port zerobin should listen on
52 '';
53 };
54
55 listenAddress = mkOption {
56 type = types.str;
57 default = "localhost";
58 example = "127.0.0.1";
59 description = ''
60 The address zerobin should listen to
61 '';
62 };
63
64 extraConfig = mkOption {
65 type = types.lines;
66 default = "";
67 example = ''
68 MENU = (
69 ('Home', '/'),
70 )
71 COMPRESSED_STATIC_FILE = True
72 '';
73 description = ''
74 Extra configuration to be appended to the 0bin config file
75 (see https://0bin.readthedocs.org/en/latest/en/options.html)
76 '';
77 };
78 };
79 };
80
81 config = mkIf (cfg.enable) {
82 users.users.${cfg.user} = optionalAttrs (cfg.user == "zerobin") {
83 isSystemUser = true;
84 group = cfg.group;
85 home = cfg.dataDir;
86 createHome = true;
87 };
88 users.groups.${cfg.group} = { };
89
90 systemd.services.zerobin = {
91 enable = true;
92 after = [ "network.target" ];
93 wantedBy = [ "multi-user.target" ];
94 serviceConfig.ExecStart = "${pkgs.zerobin}/bin/zerobin ${cfg.listenAddress} ${toString cfg.listenPort} false ${cfg.user} ${cfg.group} ${zerobin_config}";
95 serviceConfig.PrivateTmp = "yes";
96 serviceConfig.User = cfg.user;
97 serviceConfig.Group = cfg.group;
98 preStart = ''
99 mkdir -p ${cfg.dataDir}
100 chown ${cfg.user} ${cfg.dataDir}
101 '';
102 };
103 };
104}