summary refs log tree commit diff
diff options
context:
space:
mode:
authorThéophane Hufschmitt <theophane.hufschmitt@polytechnique.org>2016-04-20 09:32:11 +0200
committerThéophane Hufschmitt <theophane.hufschmitt@polytechnique.org>2016-04-25 13:18:58 +0200
commit201590fd97d44a56ebcc8ac487c6f8899fd3c153 (patch)
treecb4699444a9bdc9c7fda8c0ca16f0896cc87f5e7
parent22e2cfe92bbdb94d2722008c25967a3e9136a3fa (diff)
downloadnixpkgs-201590fd97d44a56ebcc8ac487c6f8899fd3c153.tar
nixpkgs-201590fd97d44a56ebcc8ac487c6f8899fd3c153.tar.gz
nixpkgs-201590fd97d44a56ebcc8ac487c6f8899fd3c153.tar.bz2
nixpkgs-201590fd97d44a56ebcc8ac487c6f8899fd3c153.tar.lz
nixpkgs-201590fd97d44a56ebcc8ac487c6f8899fd3c153.tar.xz
nixpkgs-201590fd97d44a56ebcc8ac487c6f8899fd3c153.tar.zst
nixpkgs-201590fd97d44a56ebcc8ac487c6f8899fd3c153.zip
zerobin service : init
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/networking/zerobin.nix102
2 files changed, 103 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 972802b2341..b238003dd0c 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -401,6 +401,7 @@
   ./services/networking/wicd.nix
   ./services/networking/wpa_supplicant.nix
   ./services/networking/xinetd.nix
+  ./services/networking/zerobin.nix
   ./services/networking/zerotierone.nix
   ./services/networking/znc.nix
   ./services/printing/cupsd.nix
diff --git a/nixos/modules/services/networking/zerobin.nix b/nixos/modules/services/networking/zerobin.nix
new file mode 100644
index 00000000000..1c524602f8e
--- /dev/null
+++ b/nixos/modules/services/networking/zerobin.nix
@@ -0,0 +1,102 @@
+{ config, pkgs, lib, nodes, ... }:
+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) {
+      users.users."${cfg.user}" =
+      if cfg.user == "zerobin" then {
+        isSystemUser = true;
+        group = cfg.group;
+        home = cfg.dataDir;
+        createHome = true;
+      }
+      else {};
+      users.groups."${cfg.group}" = {};
+
+      systemd.services.zerobin = {
+        enable = true;
+        after = [ "network-interfaces.target" ];
+        wantedBy = [ "multi-user.target" ];
+        serviceConfig.ExecStart = "${pkgs.pythonPackages.zerobin}/bin/zerobin ${cfg.listenAddress} ${toString cfg.listenPort} false ${cfg.user} ${cfg.group} ${zerobin_config}";
+        serviceConfig.PrivateTmp="yes";
+        serviceConfig.User = cfg.user;
+        serviceConfig.Group = cfg.group;
+        preStart = ''
+        mkdir -p ${cfg.dataDir}
+        chown ${cfg.user} ${cfg.dataDir}
+        '';
+      };
+    };
+  }
+