From 92c1ef1af95740077282d773242fdd1820c8d15b Mon Sep 17 00:00:00 2001 From: stuebinm Date: Sun, 7 Mar 2021 23:52:19 +0100 Subject: Added basic nixos module (and restructured some files) Right now, this is capable of setting up a running instance of picarones in a couple lines of config (both backend server and the webapp, using nginx). More options should still be added, especially to make the backend's port configurable (but this requires adding features to the haskell code) --- .gitignore | 2 +- default.nix | 80 +++++++++++++++++++++++++++++++++++++++++++++ example.nix | 15 +++++++++ picarones-elm/cover.html | 19 ----------- picarones-elm/default.nix | 24 +++++++++----- picarones-elm/index.html | 21 ++---------- picarones-elm/slide.html | 34 +++++++++++++++++++ picarones-elm/src/Cover.elm | 2 +- picarones-hs/build.nix | 15 +++++++++ picarones-hs/default.nix | 48 +++++++++------------------ pkgs.nix | 6 ++++ 11 files changed, 186 insertions(+), 80 deletions(-) create mode 100644 default.nix create mode 100644 example.nix delete mode 100644 picarones-elm/cover.html create mode 100644 picarones-elm/slide.html create mode 100644 picarones-hs/build.nix create mode 100644 pkgs.nix diff --git a/.gitignore b/.gitignore index 7d57a10..88eab70 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ */dist-newstyle/* -*/result +*result */elm-stuff/* *js 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; + }; + }; + }; + }; +} diff --git a/example.nix b/example.nix new file mode 100644 index 0000000..4c66bc9 --- /dev/null +++ b/example.nix @@ -0,0 +1,15 @@ +{config, pkgs, ...}: + +{ + imports = [ ./default.nix ]; + + services.picarones = { + enable = true; + frontend = { + enable = true; + domain = "10.233.4.2"; + }; + }; + + networking.firewall.allowedTCPPorts = [ 80 ]; +} diff --git a/picarones-elm/cover.html b/picarones-elm/cover.html deleted file mode 100644 index d92eba9..0000000 --- a/picarones-elm/cover.html +++ /dev/null @@ -1,19 +0,0 @@ - - -
- -