From 6eb992efdd68d80bc62bc7fc0562d8a2e6558096 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Mon, 6 Sep 2021 15:32:19 +0200 Subject: add nix build system and NixOS module --- module.nix | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 module.nix (limited to 'module.nix') 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 + ''; + }; + }; +} -- cgit v1.2.3