summaryrefslogtreecommitdiff
path: root/service.nix
blob: f274ba58e0d09453083f53bcae1f3c079579e872 (plain)
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
{ config, lib, pkgs, ... }:

let
  rust_features = pkgs.callPackage ./default.nix {};
  cfg = config.services.rust-features;
in
{
  options.services.rust-features = {
    enable = lib.mkEnableOption "rust-features";

    virtualHost = lib.mkOption {
      type = lib.types.str;
      description = "Name of the nginx virtualhost to set up.";
    };

    user = lib.mkOption {
      type = lib.types.str;
      description = "User account under which the rust-features service runs.";
    };

    nginx = lib.mkOption {
      type = lib.types.submodule (import <nixpkgs/nixos/modules/services/web-servers/nginx/vhost-options.nix>);
      default = {};
    };
  };

  config = lib.mkIf cfg.enable {
    services.nginx = {
      enable = true;

      virtualHosts.${cfg.virtualHost} = lib.mkMerge [
        cfg.nginx
        {
          locations."/" = {
            root = "/var/lib/rust-features/out";
          };
        }
      ];
    };

    systemd.services.rust-features = {
      serviceConfig = {
        Type = "oneshot";
        User = cfg.user;
        StateDirectory = "rust-features"; # creates /var/lib/rust-features
        WorkingDirectory = "/var/lib/rust-features";
        ExecStart = "${rust_features}/bin/rust-features";
        LogExtraFields = "log_format=logfmt";
      };
      startAt = "hourly";
    };
  };
}