summary refs log tree commit diff
path: root/nixos/modules/services/networking/ngircd.nix
blob: c0b9c98fb4bf53c653400205081aa7e2584504f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.ngircd;

  configFile = pkgs.stdenv.mkDerivation {
    name = "ngircd.conf";

    text = cfg.config;

    preferLocalBuild = true;

    buildCommand = ''
      echo -n "$text" > $out
      ${cfg.package}/sbin/ngircd --config $out --configtest
    '';
  };
in {
  options = {
    services.ngircd = {
      enable = mkEnableOption "the ngircd IRC server";

      config = mkOption {
        description = "The ngircd configuration (see ngircd.conf(5)).";

        type = types.lines;
      };

      package = mkOption {
        description = "The ngircd package.";

        type = types.package;

        default = pkgs.ngircd;
        defaultText = literalExpression "pkgs.ngircd";
      };
    };
  };

  config = mkIf cfg.enable {
    #!!! TODO: Use ExecReload (see https://github.com/NixOS/nixpkgs/issues/1988)
    systemd.services.ngircd = {
      description = "The ngircd IRC server";

      wantedBy = [ "multi-user.target" ];

      serviceConfig.ExecStart = "${cfg.package}/sbin/ngircd --config ${configFile} --nodaemon";

      serviceConfig.User = "ngircd";
    };

    users.users.ngircd = {
      isSystemUser = true;
      group = "ngircd";
      description = "ngircd user.";
    };
    users.groups.ngircd = {};

  };
}