Home

tsnet-serve-nix @main - refs - log -
-
https://git.jolheiser.com/tsnet-serve-nix.git
tsnet-serve flake, package, and module
tree log patch
fix: cfg -> instanceCfg for package Signed-off-by: jolheiser <git@jolheiser.com>
Signature
-----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgBTEvCQk6VqUAdN2RuH6bj1dNkY oOpbPWj+jw4ua1B1cAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5 AAAAQOQ0wERlrZPChRKDfw2/COrtaxJLBGOfdWsoQVC6mC+09PJ38MDoinguTu2C0tJDno pTh0v436Lo+kHAovcVTAw= -----END SSH SIGNATURE-----
jolheiser <git@jolheiser.com>
4 months ago
1 changed files, 86 additions(+), 81 deletions(-)
M module/default.nixmodule/default.nix
diff --git a/module/default.nix b/module/default.nix
index 854812cbbebb6a15e59c23a959b868c1123dcecc..c11b0d2216984bff070cfcbf5e3a1fbbd9a8d3e4 100644
--- a/module/default.nix
+++ b/module/default.nix
@@ -3,93 +3,98 @@   config,
   lib,
   pkgs,
   ...
-}: let
+}:
+let
   cfg = config.services.tsnet-serve;
-  pkg = pkgs.callPackage ../pkg {inherit pkgs;};
+  pkg = pkgs.callPackage ../pkg { inherit pkgs; };
 
-  instanceOptions = {
-    name,
-    config,
-    ...
-  }: {
-    options = {
-      enable = lib.mkEnableOption "tsnet-serve-${name}";
+  instanceOptions =
+    {
+      name,
+      config,
+      ...
+    }:
+    {
+      options = {
+        enable = lib.mkEnableOption "tsnet-serve-${name}";
 
-      user = lib.mkOption {
-        type = lib.types.str;
-        default = "tsnet-serve";
-        description = "User to run tsnet-serve";
-      };
+        user = lib.mkOption {
+          type = lib.types.str;
+          default = "tsnet-serve";
+          description = "User to run tsnet-serve";
+        };
 
-      backend = lib.mkOption {
-        type = lib.types.nullOr lib.types.str;
-        default = null;
-        description = "Target URL to proxy";
-        example = "https://localhost:3000";
-      };
+        backend = lib.mkOption {
+          type = lib.types.nullOr lib.types.str;
+          default = null;
+          description = "Target URL to proxy";
+          example = "https://localhost:3000";
+        };
 
-      hostname = lib.mkOption {
-        type = lib.types.str;
-        default = name;
-        description = "App name";
-        example = "myapp";
-      };
+        hostname = lib.mkOption {
+          type = lib.types.str;
+          default = name;
+          description = "App name";
+          example = "myapp";
+        };
 
-      funnel = lib.mkOption {
-        type = lib.types.bool;
-        default = false;
-        description = "Enable funnel mode";
-      };
+        funnel = lib.mkOption {
+          type = lib.types.bool;
+          default = false;
+          description = "Enable funnel mode";
+        };
 
-      port = lib.mkOption {
-        type = lib.types.port;
-        default = 443;
-        description = "Port to listen on";
-      };
+        port = lib.mkOption {
+          type = lib.types.port;
+          default = 443;
+          description = "Port to listen on";
+        };
 
-      mountPath = lib.mkOption {
-        type = lib.types.str;
-        default = "/";
-        description = "Path to mount proxy on";
-      };
+        mountPath = lib.mkOption {
+          type = lib.types.str;
+          default = "/";
+          description = "Path to mount proxy on";
+        };
 
-      stateDir = lib.mkOption {
-        type = lib.types.str;
-        default = "/var/lib/tsnet-serve-${name}";
-        description = "Directory to store state in";
-      };
+        stateDir = lib.mkOption {
+          type = lib.types.str;
+          default = "/var/lib/tsnet-serve-${name}";
+          description = "Directory to store state in";
+        };
 
-      authKey = lib.mkOption {
-        type = lib.types.nullOr lib.types.str;
-        default = null;
-        description = "Tailscale auth key";
-      };
+        authKey = lib.mkOption {
+          type = lib.types.nullOr lib.types.str;
+          default = null;
+          description = "Tailscale auth key";
+        };
 
-      package = lib.mkOption {
-        type = lib.types.package;
-        default = pkg;
-        description = "The tsnet-serve package to use";
+        package = lib.mkOption {
+          type = lib.types.package;
+          default = pkg;
+          description = "The tsnet-serve package to use";
+        };
       };
     };
-  };
-in {
+in
+{
   options = {
     services.tsnet-serve.instances = lib.mkOption {
       type = lib.types.attrsOf (lib.types.submodule instanceOptions);
-      default = {};
+      default = { };
       description = "Attribute set of tsnet-serve instances";
     };
   };
 
-  config = lib.mkIf (cfg.instances != {}) {
+  config = lib.mkIf (cfg.instances != { }) {
     systemd.services = lib.mapAttrs' (
       name: instanceCfg:
-        lib.nameValuePair "tsnet-serve-${name}" {
-          description = "tsnet-serve-${name}";
-          wantedBy = ["multi-user.target"];
-          after = ["network.target"];
-          serviceConfig = {
-            ExecStart = let
+      lib.nameValuePair "tsnet-serve-${name}" {
+        description = "tsnet-serve-${name}";
+        wantedBy = [ "multi-user.target" ];
+        after = [ "network.target" ];
+        serviceConfig = {
+          ExecStart =
+            let
               args =
                 lib.optionals (instanceCfg.backend != null) [
                   "--backend=${instanceCfg.backend}"
@@ -101,27 +106,27 @@                   "--listen-port=${builtins.toString instanceCfg.port}"
                   "--mount-path=${instanceCfg.mountPath}"
                   "--state-dir=${instanceCfg.stateDir}"
                 ];
-            in "${cfg.package}/bin/tsnet-serve ${lib.concatStringsSep " " args}";
-            User = instanceCfg.user;
-            Restart = "on-failure";
-            Environment = ["TS_AUTHKEY=${instanceCfg.authKey}"];
-          };
-        }
+            in
+            "${instanceCfg.package}/bin/tsnet-serve ${lib.concatStringsSep " " args}";
+          User = instanceCfg.user;
+          Restart = "on-failure";
+          Environment = [ "TS_AUTHKEY=${instanceCfg.authKey}" ];
+        };
+      }
     ) (lib.filterAttrs (name: instanceCfg: instanceCfg.enable) cfg.instances);
 
     users.users = lib.mapAttrs' (
       name: instanceCfg:
-        lib.nameValuePair instanceCfg.user {
-          isSystemUser = true;
-          group = instanceCfg.user;
-          home = instanceCfg.stateDir;
-          createHome = true;
-        }
+      lib.nameValuePair instanceCfg.user {
+        isSystemUser = true;
+        group = instanceCfg.user;
+        home = instanceCfg.stateDir;
+        createHome = true;
+      }
     ) (lib.filterAttrs (name: instanceCfg: instanceCfg.enable) cfg.instances);
 
-    users.groups = lib.mapAttrs' (
-      name: instanceCfg:
-        lib.nameValuePair instanceCfg.user {}
-    ) (lib.filterAttrs (name: instanceCfg: instanceCfg.enable) cfg.instances);
+    users.groups = lib.mapAttrs' (name: instanceCfg: lib.nameValuePair instanceCfg.user { }) (
+      lib.filterAttrs (name: instanceCfg: instanceCfg.enable) cfg.instances
+    );
   };
 }