about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/networking/alice-lg.nix
blob: fbf127d9410f6e072db659126dde74628e0d6e1e (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.alice-lg;
  settingsFormat = pkgs.formats.ini { };
in
{
  options = {
    services.alice-lg = {
      enable = mkEnableOption (lib.mdDoc "Alice Looking Glass");

      package = mkPackageOption pkgs "alice-lg" { };

      settings = mkOption {
        type = settingsFormat.type;
        default = { };
        description = lib.mdDoc ''
          alice-lg configuration, for configuration options see the example on [github](https://github.com/alice-lg/alice-lg/blob/main/etc/alice-lg/alice.example.conf)
        '';
        example = literalExpression ''
          {
            server = {
              # configures the built-in webserver and provides global application settings
              listen_http = "127.0.0.1:7340";
              enable_prefix_lookup = true;
              asn = 9033;
              store_backend = postgres;
              routes_store_refresh_parallelism = 5;
              neighbors_store_refresh_parallelism = 10000;
              routes_store_refresh_interval = 5;
              neighbors_store_refresh_interval = 5;
            };
            postgres = {
              url = "postgres://postgres:postgres@localhost:5432/alice";
              min_connections = 2;
              max_connections = 128;
            };
            pagination = {
              routes_filtered_page_size = 250;
              routes_accepted_page_size = 250;
              routes_not_exported_page_size = 250;
            };
          }
        '';
      };
    };
  };

  config = lib.mkIf cfg.enable {
    environment = {
      etc."alice-lg/alice.conf".source = settingsFormat.generate "alice-lg.conf" cfg.settings;
    };
    systemd.services = {
      alice-lg = {
        wants = [ "network.target" ];
        after = [ "network.target" ];
        wantedBy = [ "multi-user.target" ];
        description = "Alice Looking Glass";
        serviceConfig = {
          DynamicUser = true;
          Type = "simple";
          Restart = "on-failure";
          RestartSec = 15;
          ExecStart = "${cfg.package}/bin/alice-lg";
          StateDirectoryMode = "0700";
          UMask = "0007";
          CapabilityBoundingSet = "";
          NoNewPrivileges = true;
          ProtectSystem = "strict";
          PrivateTmp = true;
          PrivateDevices = true;
          PrivateUsers = true;
          ProtectHostname = true;
          ProtectClock = true;
          ProtectKernelTunables = true;
          ProtectKernelModules = true;
          ProtectKernelLogs = true;
          ProtectControlGroups = true;
          RestrictAddressFamilies = [ "AF_INET AF_INET6" ];
          LockPersonality = true;
          MemoryDenyWriteExecute = true;
          RestrictRealtime = true;
          RestrictSUIDSGID = true;
          PrivateMounts = true;
          SystemCallArchitectures = "native";
          SystemCallFilter = "~@clock @privileged @cpu-emulation @debug @keyring @module @mount @obsolete @raw-io @reboot @setuid @swap";
          BindReadOnlyPaths = [
            "-/etc/resolv.conf"
            "-/etc/nsswitch.conf"
            "-/etc/ssl/certs"
            "-/etc/static/ssl/certs"
            "-/etc/hosts"
            "-/etc/localtime"
          ];
        };
      };
    };
  };
}