diff options
Diffstat (limited to 'service.nix')
-rw-r--r-- | service.nix | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/service.nix b/service.nix new file mode 100644 index 0000000..f274ba5 --- /dev/null +++ b/service.nix @@ -0,0 +1,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"; + }; + }; +} |