nginx.nix 792 Bytes
Newer Older
Matthias Adamczyk's avatar
Matthias Adamczyk committed
1
2
3
{ config, lib, pkgs, ... }:

let
Matthias Adamczyk's avatar
Fix CI    
Matthias Adamczyk committed
4
  cfg = config.finf.vnstat.nginx;
Matthias Adamczyk's avatar
Matthias Adamczyk committed
5
6

in {
Matthias Adamczyk's avatar
Fix CI    
Matthias Adamczyk committed
7
  options.finf.vnstat.nginx = with lib; {
Matthias Adamczyk's avatar
Matthias Adamczyk committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    enable = mkEnableOption "nginx virtual host for traffic pics";

    domain = mkOption {
      type = types.str;
      default = "${config.networking.hostName}.${config.networking.domain}";
    };

    subdirectory = mkOption {
      type = types.str;
      default = "/traffic/";
    };
  };

  config = lib.mkIf cfg.enable {
    assertions = [
      ({
Matthias Adamczyk's avatar
Fix CI    
Matthias Adamczyk committed
24
        assertion = config.finf.vnstat.generateImages;
Matthias Adamczyk's avatar
Matthias Adamczyk committed
25
26
27
28
29
30
31
32
33
34
35
        message = "nginx requires vnstat.generateImages == true";
      })
    ];

    services.nginx.virtualHosts.${cfg.domain} = {
      locations.${cfg.subdirectory}.alias = "/var/lib/vnstati/";
    };

    users.users.nginx.extraGroups = [ "vnstatd" ];
  };
}