summaryrefslogtreecommitdiff
path: root/Biz/Storybook.nix
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2024-12-20 13:21:43 -0500
committerBen Sima <ben@bsima.me>2024-12-21 10:08:11 -0500
commit32d31ae8d1ef5d5aeb03a7fe7e6a294e14905505 (patch)
tree4a248394a7c49682f9ef7538e3033fbea5117690 /Biz/Storybook.nix
parent87ead51331bc57326882055e1635a84c2d409af7 (diff)
Build and deploy storybook
I put the storybook into a new Biz.nix deploy target. The idea here is that any Biz/* targets should be hosted by this one VM for simplicity. Over time I can grow this as need be, but this should work to host a few services.
Diffstat (limited to 'Biz/Storybook.nix')
-rw-r--r--Biz/Storybook.nix78
1 files changed, 78 insertions, 0 deletions
diff --git a/Biz/Storybook.nix b/Biz/Storybook.nix
new file mode 100644
index 0000000..692b4e9
--- /dev/null
+++ b/Biz/Storybook.nix
@@ -0,0 +1,78 @@
+{ options, lib, config, pkgs, ... }:
+
+let
+ cfg = config.services.storybook;
+ rootDomain = "bensima.com";
+ ports = import ../Omni/Cloud/Ports.nix;
+in {
+ options.services.storybook = {
+ enable = lib.mkEnableOption "Enable the storybook service";
+ port = lib.mkOption {
+ type = lib.types.int;
+ default = 3000;
+ description = ''
+ The port on which storybook will listen for
+ incoming HTTP traffic.
+ '';
+ };
+ dataDir = lib.mkOption {
+ type = lib.types.path;
+ default = "/var/storybook/";
+ description = "Data dir location";
+ };
+ package = lib.mkOption {
+ type = lib.types.package;
+ description = "storybook package to use";
+ };
+ };
+ config = lib.mkIf cfg.enable {
+ systemd.services.storybook = {
+ path = [ cfg.package pkgs.git ];
+ wantedBy = [ "multi-user.target" ];
+ preStart = ''
+ # these must be manually created
+ test -d /run/storybook
+ test -f /run/storybook/env
+ # this can be generated
+ mkdir -p ${cfg.dataDir}
+ '';
+ script = ''
+ ${cfg.package}/bin/storybook
+ '';
+ description = ''
+ Storybook
+ '';
+ serviceConfig = {
+ Environment =
+ [ "PORT=${toString cfg.port}" "AREA=Live" "DATA_DIR=${cfg.dataDir}" ];
+ EnvironmentFile = "/run/storybook/env";
+ KillSignal = "INT";
+ Type = "simple";
+ Restart = "on-abort";
+ RestartSec = "1";
+ };
+ };
+
+ # TODO: nginx web stuff
+ services.nginx = {
+ enable = true;
+ recommendedGzipSettings = true;
+ recommendedOptimisation = true;
+ recommendedProxySettings = true;
+ recommendedTlsSettings = true;
+ statusPage = true;
+
+ user = "nginx";
+ group = "nginx";
+
+ virtualHosts."storybook.${rootDomain}" = {
+ forceSSL = true;
+ enableACME = true;
+ locations."/".proxyPass = "http://localhost:${toString cfg.port}";
+ # useACMEHost = rootDomain;
+ };
+ };
+
+ networking.firewall.allowedTCPPorts = [ ports.ssh ports.http ports.https ];
+ };
+}