summaryrefslogtreecommitdiff
path: root/service.nix
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2025-03-09 13:48:00 +0100
committerMartin Fischer <martin@push-f.com>2025-03-09 21:36:04 +0100
commit232f1499bb9a2cc85a63abcc1c22776ef77781fb (patch)
tree50b9b429140e6d597090e5d1264496555fd0edf7 /service.nix
parent42c737aa1a7731170e8369482f96b557a1bd7a36 (diff)
build: introduce NixOS package & serviceHEADmaster
Diffstat (limited to 'service.nix')
-rw-r--r--service.nix52
1 files changed, 52 insertions, 0 deletions
diff --git a/service.nix b/service.nix
new file mode 100644
index 0000000..fcd665e
--- /dev/null
+++ b/service.nix
@@ -0,0 +1,52 @@
+{ config, lib, pkgs, ... }:
+
+let
+ osm_proposals = pkgs.callPackage ./default.nix {};
+ cfg = config.services.osm_proposals;
+in
+{
+ options.services.osm_proposals = {
+ enable = lib.mkEnableOption "osm_proposals";
+
+ virtualHost = lib.mkOption {
+ type = lib.types.str;
+ description = "Name of the nginx virtualhost to set up.";
+ };
+
+ 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 = "${osm_proposals}/share/osm-proposals";
+ };
+ locations."=/proposals.json" = {
+ extraConfig = ''
+ alias /var/lib/osm-proposals/proposals.json;
+ '';
+ };
+ }
+ ];
+ };
+
+ systemd.services.osm-proposals = {
+ serviceConfig = {
+ Type = "oneshot";
+ StateDirectory = "osm-proposals"; # creates /var/lib/osm-proposals
+ ExecStart = "${osm_proposals}/bin/osm-proposals /var/lib/osm-proposals/proposals.json";
+ # Not using DynamicUser because then the StateDirectory becomes unreadable
+ # by other users, even when setting StateDirectoryMode for some reason.
+ };
+ startAt = "hourly";
+ };
+ };
+}