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