diff options
author | Ben Sima <ben@bsima.me> | 2019-02-16 20:51:58 -0800 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2019-02-16 20:51:58 -0800 |
commit | cf5b024e189cb4ed85f80b521cf9e0e5dc5b5070 (patch) | |
tree | f579a2ff069862856e6a1667426769c165aaa079 | |
parent | 225f2c575d18f080daa82d634af7f1fde4f03809 (diff) |
Make port configurable
-rw-r--r-- | configuration.nix | 10 | ||||
-rw-r--r-- | ibb/Main.hs | 8 | ||||
-rw-r--r-- | ibb/module.nix | 47 |
3 files changed, 43 insertions, 22 deletions
diff --git a/configuration.nix b/configuration.nix index 775bc99..adf90d3 100644 --- a/configuration.nix +++ b/configuration.nix @@ -2,6 +2,7 @@ let bensIp = "68.107.97.20"; + ibbPort = "3000"; in { nixpkgs.config.packageOverrides = pkgs: { @@ -12,7 +13,10 @@ in services = { - ibb.enable = true; + ibb = { + enable = true; + port = ibbPort; + }; nginx = { enable = true; @@ -22,7 +26,7 @@ in recommendedTlsSettings = true; virtualHosts = { "simatime.com".locations."/".proxyPass = "http://${bensIp}:8000"; - "dev.simatime.com".locations."/".proxyPass = "http://${bensIp}:3000"; + "dev.simatime.com".locations."/".proxyPass = "http://${bensIp}:${ibbPort}"; "hero.simatime.com".locations."/".proxyPass = "http://${bensIp}:3001"; "tv.simatime.com".locations."/".proxyPass = "http://${bensIp}:8096"; # emby runs on port 8096 "influencedbybooks.com" = { @@ -30,7 +34,7 @@ in enableACME = true; locations = { "/" = { - proxyPass = "http://localhost:3000"; + proxyPass = "http://localhost:${ibbPort}"; }; }; }; diff --git a/ibb/Main.hs b/ibb/Main.hs index 544b0c8..05e7738 100644 --- a/ibb/Main.hs +++ b/ibb/Main.hs @@ -3,6 +3,7 @@ module Main where +import Data.Maybe (fromMaybe) import Data.ByteString.Lazy (ByteString) import Data.Text.Lazy (Text) import Data.Text.Lazy.Encoding (encodeUtf8) @@ -13,6 +14,7 @@ import Text.Hamlet (shamlet) import Text.Lucius (lucius, renderCss) import Web.Scotty (ActionM, scotty, get, html, raw, setHeader) import Influencers +import System.Environment (lookupEnv) render :: Html -> ActionM () render = html . renderHtml @@ -21,7 +23,11 @@ css :: ByteString -> ActionM () css src = setHeader "content-type" "text/css" >> raw src main :: IO () -main = scotty 3000 $ do +main = do + port <- read <$> fromMaybe "3000" <$> lookupEnv "PORT" :: IO Int + scotty port routes + +routes = do get "/" $ render homepage get "/custom.css" $ css stylesheet diff --git a/ibb/module.nix b/ibb/module.nix index b4f7609..e2d4dd0 100644 --- a/ibb/module.nix +++ b/ibb/module.nix @@ -7,24 +7,35 @@ let cfg = config.services.ibb; -in { - options.services.ibb.enable = lib.mkEnableOption "Enable the IBB service"; - config = lib.mkIf cfg.enable { - systemd.services.ibb = { - path = with pkgs; [ ibb bash ]; - wantedBy = [ "multi-user.target" ]; - script = '' - ./bin/ibb - ''; - description = '' - Influenced By Books website - ''; - serviceConfig = { - WorkingDirectory=pkgs.ibb; - KillSignal="INT"; - Type = "simple"; - Restart = "on-abort"; - RestartSec = "10"; +in +{ + options.services.ibb = { + enable = lib.mkEnableOption "Enable the IBB service"; + port = lib.mkOption { + type = lib.types.string; + default = "3000"; + description = '' + The port on which IBB will listen for + incoming HTTP traffic. + ''; + }; + }; + config = lib.mkIf cfg.enable { + systemd.services.ibb = { + path = with pkgs; [ ibb bash ]; + wantedBy = [ "multi-user.target" ]; + script = '' + PORT=${cfg.port} ./bin/ibb + ''; + description = '' + Influenced By Books website + ''; + serviceConfig = { + WorkingDirectory=pkgs.ibb; + KillSignal="INT"; + Type = "simple"; + Restart = "on-abort"; + RestartSec = "10"; }; }; }; |