diff options
Diffstat (limited to '')
-rw-r--r-- | default.nix | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..d739a4c --- /dev/null +++ b/default.nix @@ -0,0 +1,80 @@ +{config, lib, pkgs, ...}: +let + picarones = import ./pkgs.nix { inherit pkgs; }; +in +with lib; +{ + options.services.picarones = { + enable = mkOption { + default = false; + example = true; + type = types.bool; + description = "'next slide please' as a service"; + }; + package = mkOption { + description = "the server package to use"; + default = picarones.picarones-hs; + type = types.package; + }; + port = mkOption { + description = "port at which the backend server should listen."; + default = 9000; + type = types.int; + }; + frontend = { + enable = mkOption { + description = "Whether to setup nginx to deliver the picarones frontend"; + default = true; + type = types.bool; + }; + package = mkOption { + description = "Which package provides the frontend app."; + default = picarones.picarones-elm; + type = types.package; + }; + domain = mkOption { + description = "Which domain nginx should listen on."; + default = ""; + type = types.str; + }; + proxyBackend = mkOption { + description = "whether to set up a proxy for the backend using nginx (on the same domain)."; + default = false; + type = types.bool; + }; + config = mkOption { + description = "extra options for nginx."; + default = {}; + type = types.attrs; + }; + }; + }; + + config = let cfg = config.services.picarones; in { + systemd.services.picarones-hs = { + description = "picarones backend server"; + path = [ cfg.package ]; + wantedBy = [ "multi-user.target" ]; + script = '' + ${cfg.package}/bin/picarones-hs + ''; + }; + + services.nginx = mkIf cfg.frontend.enable { + enable = true; + virtualHosts.${cfg.frontend.domain} = cfg.frontend.config // { + root = + # need to do it this (long) way since a user may change this value outside of this module + let ssl = config.services.nginx.virtualHosts.${cfg.frontend.domain}.enableSSL; + in (cfg.frontend.package.override { + baseurl = (if ssl then "https://" else "http://") + cfg.frontend.domain; + serverurl = (if ssl then "wss" else "ws") + "://${cfg.frontend.domain}/websocket"; + }).outPath; + locations."/websocket" = { + proxyPass = "http://localhost:9160"; + proxyWebsockets = true; + }; + }; + }; + }; +} |