summaryrefslogtreecommitdiff
path: root/service.nix
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2025-04-04 15:07:55 +0200
committerMartin Fischer <martin@push-f.com>2025-04-05 12:10:36 +0200
commitd8b675d3670a70df15ec46dfd9a1bb9f801aae41 (patch)
tree9a8d5188081c912ba463ad06f005983ad82d6836 /service.nix
parentb6e94ce2128968d83b0714904b251de434b58ab2 (diff)
build: introduce Nix package and NixOS service
Diffstat (limited to 'service.nix')
-rw-r--r--service.nix53
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";
+ };
+ };
+}