Commit 2882a766 authored by Martin Weinelt's avatar Martin Weinelt
Browse files

nixos/pinnwand: convert to freeform type, drop reaper unit

parent 6b5ed124
Loading
Loading
Loading
Loading
+58 −39
Original line number Diff line number Diff line
@@ -19,29 +19,66 @@ in
    };

    settings = mkOption {
      type = format.type;
      default = {};
      description = lib.mdDoc ''
        Your {file}`pinnwand.toml` as a Nix attribute set. Look up
        possible options in the [pinnwand.toml-example](https://github.com/supakeen/pinnwand/blob/master/pinnwand.toml-example).
        possible options in the [documentation](https://pinnwand.readthedocs.io/en/v${pkgs.pinnwand.version}/configuration.html).
      '';
      type = types.submodule {
        freeformType = format.type;
        options = {
          database_uri = mkOption {
            type = types.str;
            default = "sqlite:////var/lib/pinnwand/pinnwand.db";
            example = "sqlite:///:memory";
            description = lib.mdDoc ''
              Database URI compatible with [SQLAlchemyhttps://docs.sqlalchemy.org/en/14/core/engines.html#database-urls].

              Additional packages may need to be introduced into the environment for certain databases.
            '';
      default = {};
    };
          };

  config = mkIf cfg.enable {
    services.pinnwand.settings = {
      database_uri = mkDefault "sqlite:////var/lib/pinnwand/pinnwand.db";
      paste_size = mkDefault 262144;
      paste_help = mkDefault ''
          paste_size = mkOption {
            type = types.ints.positive;
            default = 262144;
            example = 524288;
            description = lib.mdDoc ''
              Maximum size of a paste in bytes.
            '';
          };
          paste_help = mkOption {
            type = types.str;
            default = ''
              <p>Welcome to pinnwand, this site is a pastebin. It allows you to share code with others. If you write code in the text area below and press the paste button you will be given a link you can share with others so they can view your code as well.</p><p>People with the link can view your pasted code, only you can remove your paste and it expires automatically. Note that anyone could guess the URI to your paste so don't rely on it being private.</p>
              '';
      footer = mkDefault ''
            description = lib.mdDoc ''
              Raw HTML help text shown in the header area.
            '';
          };
          footer = mkOption {
            type = types.str;
            default = ''
              View <a href="//github.com/supakeen/pinnwand" target="_BLANK">source code</a>, the <a href="/removal">removal</a> or <a href="/expiry">expiry</a> stories, or read the <a href="/about">about</a> page.
            '';
            description = lib.mdDoc ''
              The footer in raw HTML.
            '';
          };
        };
      };
    };
  };

  config = mkIf cfg.enable {
    systemd.services.pinnwand = {
      description = "Pinnwannd HTTP Server";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];

    systemd.services = let
      hardeningOptions = {
      unitConfig.Documentation = "https://pinnwand.readthedocs.io/en/latest/";

      serviceConfig = {
        ExecStart = "${pkgs.pinnwand}/bin/pinnwand --configuration-path ${configFile} http --port ${toString cfg.port}";
        User = "pinnwand";
        DynamicUser = true;

@@ -72,32 +109,14 @@ in
        RestrictNamespaces = true;
        RestrictRealtime = true;
        SystemCallArchitectures = "native";
        SystemCallFilter = "@system-service";
        SystemCallFilter = [
          "@system-service"
          "~@privileged"
        ];
        UMask = "0077";
      };

      command = "${pkgs.pinnwand}/bin/pinnwand --configuration-path ${configFile}";
    in {
      pinnwand = {
        description = "Pinnwannd HTTP Server";
        after = [ "network.target" ];
        wantedBy = [ "multi-user.target" ];

        unitConfig.Documentation = "https://pinnwand.readthedocs.io/en/latest/";

        serviceConfig = {
          ExecStart = "${command} http --port ${toString(cfg.port)}";
        } // hardeningOptions;
      };

      pinnwand-reaper = {
        description = "Pinnwand Reaper";
        startAt = "daily";

        serviceConfig = {
          ExecStart = "${command} -vvvv reap";  # verbosity increased to show number of deleted pastes
        } // hardeningOptions;
      };
    };
  };

  meta.buildDocsInSandbox = false;
}