2 inputs.flake-utils.url = "github:numtide/flake-utils";
3 inputs.nixpkgs.url = "github:NixOS/nixpkgs";
5 description = "Pastebin-like service";
7 outputs = { self, flake-utils, nixpkgs }: flake-utils.lib.eachDefaultSystem (system:
9 pkgs = import nixpkgs { inherit system; overlays = []; };
12 checks = pkgs.lib.optionalAttrs (builtins.elem system pkgs.lib.systems.doubles.linux) {
14 let testing = import (nixpkgs + "/nixos/lib/testing-python.nix") { inherit system; };
17 server = { pkgs, ... }: {
18 imports = [ self.nixosModule ];
20 environment.systemPackages = [ pkgs.curl ];
23 adminAddr = "foo@example.org";
25 ProxyPass / unix:///run/paste/gunicorn.sock|http://localhost/
26 ProxyPassReverse / unix:///run/paste/gunicorn.sock|http://localhost/
29 services.paste.enable = true;
35 server.wait_for_unit("httpd.service")
36 server.wait_for_unit("paste.service")
37 server.wait_until_succeeds("[ -S /run/paste/gunicorn.sock ]", 10)
38 server.succeed("curl -f http://localhost/")
39 server.succeed("curl -f http://localhost/ | grep -q 'Get the source'")
44 nixosModule = { config, lib, pkgs, ... }:
46 cfg = config.services.paste;
50 enable = lib.mkOption {
51 type = lib.types.bool;
53 description = "Whether to enable the pastebin service";
56 dataDir = lib.mkOption {
57 type = lib.types.path;
58 default = "/var/lib/paste";
60 The directory where Paste stores its data.
64 socketsDir = lib.mkOption {
66 default = "/run/paste";
67 description = "Socket which is used for communication with Paste.";
70 webDirectory = lib.mkOption {
71 type = lib.types.nullOr lib.types.str;
73 description = "Subdirectory url to which the app will be served";
77 systemdStateDirectory = lib.mkOption {
79 # Use ReadWritePaths= instead if varDir is outside of /var/lib
80 default = assert lib.strings.hasPrefix "/var/lib/" cfg.dataDir;
81 lib.strings.removePrefix "/var/lib/" cfg.dataDir;
83 Adjusted paste data directory for systemd
87 systemdRuntimeDirectory = lib.mkOption {
89 # Use ReadWritePaths= instead if socketsDir is outside of /run
90 default = assert lib.strings.hasPrefix "/run/" cfg.socketsDir;
91 lib.strings.removePrefix "/run/" cfg.socketsDir;
93 Adjusted paste sockets directory for systemd
97 sockets = lib.mkOption {
98 type = lib.types.attrsOf lib.types.path;
100 pid = "${cfg.socketsDir}/gunicorn.pid";
101 gunicorn = "${cfg.socketsDir}/gunicorn.sock";
111 config = lib.mkIf cfg.enable {
112 systemd.services.paste = {
113 description = "Pastebin like service";
114 after = [ "network.target" ];
115 wantedBy = [ "multi-user.target" ];
118 Environment = pkgs.lib.optionals (cfg.webDirectory != null) [ "SCRIPT_NAME=${cfg.webDirectory}" ];
120 User = config.services.httpd.user;
122 python = pkgs.python3.withPackages (p: [p.gunicorn p.flask p.pygments p.python_magic ]);
124 "${python}/bin/gunicorn -w4 -p ${cfg.sockets.pid} -e PASTE_DIRECTORY=${cfg.dataDir} --bind unix:${cfg.sockets.gunicorn} --chdir ${./paste} paste:app";
127 PIDFile = cfg.sockets.pid;
128 RuntimeDirectory = cfg.systemdRuntimeDirectory;
129 StateDirectory = cfg.systemdStateDirectory;
130 StandardOutput = "journal";
131 StandardError = "inherit";