at 24.11-pre 2.5 kB view raw
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 "0bin"; 16 17 dataDir = mkOption { 18 type = types.str; 19 default = "/var/lib/zerobin"; 20 description = '' 21 Path to the 0bin data directory 22 ''; 23 }; 24 25 user = mkOption { 26 type = types.str; 27 default = "zerobin"; 28 description = '' 29 The user 0bin should run as 30 ''; 31 }; 32 33 group = mkOption { 34 type = types.str; 35 default = "zerobin"; 36 description = '' 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 = '' 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 = '' 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 = '' 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 optionalAttrs (cfg.user == "zerobin") { 79 isSystemUser = true; 80 group = cfg.group; 81 home = cfg.dataDir; 82 createHome = true; 83 }; 84 users.groups.${cfg.group} = {}; 85 86 systemd.services.zerobin = { 87 enable = true; 88 after = [ "network.target" ]; 89 wantedBy = [ "multi-user.target" ]; 90 serviceConfig.ExecStart = "${pkgs.zerobin}/bin/zerobin ${cfg.listenAddress} ${toString cfg.listenPort} false ${cfg.user} ${cfg.group} ${zerobin_config}"; 91 serviceConfig.PrivateTmp="yes"; 92 serviceConfig.User = cfg.user; 93 serviceConfig.Group = cfg.group; 94 preStart = '' 95 mkdir -p ${cfg.dataDir} 96 chown ${cfg.user} ${cfg.dataDir} 97 ''; 98 }; 99 }; 100 } 101