{ 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 ); 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"; }; }; }