From d95b74e84eb4e71c2481ecacc309c119b8a2c447 Mon Sep 17 00:00:00 2001
From: Alexander Foremny <aforemny@posteo.de>
Date: Fri, 15 Mar 2024 06:45:41 +0100
Subject: agame: init

---
 modules/agame/default.nix         | 13 +++++++++++++
 nix/sources.json                  |  6 ++++++
 pkgs/agame/default.nix            |  7 +++++++
 systems/system1/configuration.nix |  5 +++++
 4 files changed, 31 insertions(+)
 create mode 100644 modules/agame/default.nix
 create mode 100644 pkgs/agame/default.nix

diff --git a/modules/agame/default.nix b/modules/agame/default.nix
new file mode 100644
index 0000000..0a8657d
--- /dev/null
+++ b/modules/agame/default.nix
@@ -0,0 +1,13 @@
+{ config, lib, pkgs, ... }:
+let cfg = config.services.agame; in
+{
+  options.services.agame.enable = lib.mkEnableOption "agame server";
+
+  config = lib.mkIf cfg.enable {
+    environment.systemPackages = [ pkgs.agame ];
+    networking.firewall.allowedUDPPorts = [ 16384 ];
+    systemd.services.agame.after = [ "network.target" ];
+    systemd.services.agame.script = "${pkgs.agame}/bin/agame --server";
+    systemd.services.agame.wantedBy = [ "multi-user.target" ];
+  };
+}
diff --git a/nix/sources.json b/nix/sources.json
index 8c5ac7a..654686a 100644
--- a/nix/sources.json
+++ b/nix/sources.json
@@ -5,6 +5,12 @@
         "rev": "9f2d5ae570c120f19434f03eb20ab2c3ecf36e0c",
         "type": "git"
     },
+    "agame": {
+        "branch": "main",
+        "repo": "git@code.nomath.org:~/agame",
+        "rev": "1e162629da53373f0e2502014d42c7636412e67e",
+        "type": "git"
+    },
     "feed-nomath-org": {
         "branch": "main",
         "repo": "git@code.nomath.org:~/feed-nomath-org",
diff --git a/pkgs/agame/default.nix b/pkgs/agame/default.nix
new file mode 100644
index 0000000..97e0de7
--- /dev/null
+++ b/pkgs/agame/default.nix
@@ -0,0 +1,7 @@
+{}:
+let
+  sources = import ../../nix/sources.nix;
+  # note: uses nixpkgs-unstable
+  pkgs = import (import "${sources.agame}/nix/sources.nix").nixpkgs { };
+in
+pkgs.callPackage "${sources.agame}/agame.nix" { }
diff --git a/systems/system1/configuration.nix b/systems/system1/configuration.nix
index 2502212..1ac4b4b 100644
--- a/systems/system1/configuration.nix
+++ b/systems/system1/configuration.nix
@@ -7,6 +7,7 @@
     ../../configs
     # TODO auto-load modules
     ../../modules/abuilder
+    ../../modules/agame
     ../../modules/fysiweb-capabilities
     ../../modules/fysiweb-secrets
   ];
@@ -90,5 +91,9 @@
     {
       fysiweb-apps.public.grafana.grafana-nomath-org.domain = "grafana.nomath.org";
     }
+    # enable agame server
+    {
+      services.agame.enable = true;
+    }
   ];
 }
-- 
cgit v1.2.3