aboutsummaryrefslogtreecommitdiff
path: root/module.nix
diff options
context:
space:
mode:
Diffstat (limited to 'module.nix')
-rw-r--r--module.nix58
1 files changed, 58 insertions, 0 deletions
diff --git a/module.nix b/module.nix
new file mode 100644
index 0000000..169db9f
--- /dev/null
+++ b/module.nix
@@ -0,0 +1,58 @@
+{ config, lib, pkgs, ... }:
+
+let uplcg-pkgs = import ./default.nix {inherit pkgs; };
+in
+{
+ options.services.uplcg = with lib; {
+ enable = mkOption {
+ type = types.bool;
+ default = false;
+ };
+ cards = mkOption {
+ type = with types; nullOr (lazyAttrsOf (lazyAttrsOf (oneOf [
+ (listOf str)
+ bool
+ ])));
+ default = null;
+ };
+ cardsPath = mkOption {
+ type = types.nullOr types.path;
+ default = null;
+ };
+ port = mkOption {
+ type = types.port;
+ default = 4001;
+ };
+ domain = mkOption {
+ type = types.str;
+ default = "localhost";
+ };
+ };
+
+ config =
+ let cfg = config.services.uplcg;
+ in lib.mkIf cfg.enable {
+ systemd.services.uplcg = {
+ description = "The Untitled Programming Language Card Game";
+ wantedBy = [ "multi-user.target" ];
+ after = [ "network.target" ];
+ environment = {
+ "UPLCG_HOSTNAME" = cfg.domain;
+ "UPLCG_PORT" = builtins.toString cfg.port;
+ };
+ script = ''
+ cd ${if cfg.cards != null || cfg.cardsPath != null
+ then uplcg-pkgs.client.override {
+ cards =
+ if cfg.cards == null
+ then cfg.cardsPath
+ else pkgs.writeText "uplcg-cards"
+ (lib.generators.toYAML {} cfg.cards);
+ }
+ else uplcg-pkgs.client
+ }
+ ${uplcg-pkgs.server}/bin/uplcg-server
+ '';
+ };
+ };
+}