Unverified Commit e20e12a9 authored by Bruno BELANYI's avatar Bruno BELANYI Committed by GitHub
Browse files

Merge pull request #330956 from DCsunset/gotify-module-update

nixos/gotify-server: support all config options and custom package
parents a071069e a191e88a
Loading
Loading
Loading
Loading
+68 −27
Original line number Diff line number Diff line
{ pkgs, lib, config, ... }:

with lib;
{
  pkgs,
  lib,
  config,
  ...
}:

let
  cfg = config.services.gotify;
in {
  options = {
    services.gotify = {
      enable = mkEnableOption "Gotify webserver";
in
{
  imports = [
    (lib.mkRenamedOptionModule
      [
        "services"
        "gotify"
        "port"
      ]
      [
        "services"
        "gotify"
        "environment"
        "GOTIFY_SERVER_PORT"
      ]
    )
  ];

  options.services.gotify = {
    enable = lib.mkEnableOption "Gotify webserver";

    package = lib.mkPackageOption pkgs "gotify-server" { };

      port = mkOption {
        type = types.port;
    environment = lib.mkOption {
      type = lib.types.attrsOf (
        lib.types.oneOf [
          lib.types.str
          lib.types.int
        ]
      );
      default = { };
      example = {
        GOTIFY_SERVER_PORT = 8080;
        GOTIFY_DATABASE_DIALECT = "sqlite3";
      };
      description = ''
          Port the server listens to.
        Config environment variables for the gotify-server.
        See https://gotify.net/docs/config for more details.
      '';
    };

      stateDirectoryName = mkOption {
        type = types.str;
    environmentFiles = lib.mkOption {
      type = lib.types.listOf lib.types.path;
      default = [ ];
      description = ''
        Files containing additional config environment variables for gotify-server.
        Secrets should be set in environmentFiles instead of environment.
      '';
    };

    stateDirectoryName = lib.mkOption {
      type = lib.types.str;
      default = "gotify-server";
      description = ''
        The name of the directory below {file}`/var/lib` where
@@ -25,25 +66,25 @@ in {
      '';
    };
  };
  };

  config = mkIf cfg.enable {
  config = lib.mkIf cfg.enable {
    systemd.services.gotify-server = {
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];
      description = "Simple server for sending and receiving messages";

      environment = {
        GOTIFY_SERVER_PORT = toString cfg.port;
      };
      environment = lib.mapAttrs (_: toString) cfg.environment;

      serviceConfig = {
        WorkingDirectory = "/var/lib/${cfg.stateDirectoryName}";
        StateDirectory = cfg.stateDirectoryName;
        EnvironmentFile = cfg.environmentFiles;
        Restart = "always";
        DynamicUser = "yes";
        ExecStart = "${pkgs.gotify-server}/bin/server";
        DynamicUser = true;
        ExecStart = lib.getExe cfg.package;
      };
    };
  };

  meta.maintainers = with lib.maintainers; [ DCsunset ];
}
+3 −1
Original line number Diff line number Diff line
@@ -9,7 +9,9 @@ import ./make-test-python.nix ({ pkgs, lib, ...} : {

    services.gotify = {
      enable = true;
      port = 3000;
      environment = {
        GOTIFY_SERVER_PORT = 3000;
      };
    };
  };