diff --git a/hosts/Hevana/default.nix b/hosts/Hevana/default.nix index f7b4bb9..ca80aec 100644 --- a/hosts/Hevana/default.nix +++ b/hosts/Hevana/default.nix @@ -229,6 +229,11 @@ in syncthing = { enable = true; home = "${services-root}/syncthing/aires"; + web = { + enable = true; + port = 8080; + public = true; + }; }; }; }; diff --git a/hosts/Khanda/default.nix b/hosts/Khanda/default.nix index f847f93..d53d745 100644 --- a/hosts/Khanda/default.nix +++ b/hosts/Khanda/default.nix @@ -83,7 +83,14 @@ in users.aires = { enable = true; - services.syncthing.enable = true; + services.syncthing = { + enable = true; + enableTray = true; + web = { + enable = true; + port = 8080; + }; + }; }; }; } diff --git a/hosts/Shura/default.nix b/hosts/Shura/default.nix index f50a328..efaa74b 100644 --- a/hosts/Shura/default.nix +++ b/hosts/Shura/default.nix @@ -108,15 +108,13 @@ in services.syncthing = { enable = true; enableTray = true; + web = { + enable = true; + port = 8080; + }; }; }; - gremlin = { - enable = true; - services.syncthing = { - enable = true; - enableTray = true; - }; - }; + gremlin.enable = true; }; }; diff --git a/modules/users/aires/default.nix b/modules/users/aires/default.nix index fe6790d..c66b737 100644 --- a/modules/users/aires/default.nix +++ b/modules/users/aires/default.nix @@ -23,6 +23,15 @@ in type = lib.types.str; description = "Where to store Syncthing's configuration files"; }; + web = { + enable = lib.mkEnableOption "Enables the Syncthing web UI."; + port = lib.mkOption { + type = lib.types.int; + default = 8384; + description = "The port to host Syncthing web on."; + }; + public = lib.mkEnableOption "Whether to expose the Syncthing web UI to the network."; + }; }; }; }; @@ -120,7 +129,7 @@ in }; }) - # Enable Syncthing + # Configure Syncthing (lib.mkIf cfg.services.syncthing.enable { users.users.aires.packages = [ pkgs.syncthing ]; @@ -128,18 +137,25 @@ in config.aux.system.ui.flatpak.enable && cfg.services.syncthing.enableTray ) [ "io.github.martchus.syncthingtray" ]; - # Open port 8080 - networking.firewall.allowedTCPPorts = [ 8080 ]; + # If the web UI is public, open the port in the firewall + networking.firewall.allowedTCPPorts = + with cfg.services.syncthing.web; + lib.mkIf (enable && public) [ port ]; home-manager.users.aires = { - # Syncthing options services.syncthing = { enable = true; - extraOptions = [ - "--gui-address=0.0.0.0:8080" - "--home=${cfg.services.syncthing.home}" - "--no-default-folder" - ]; + extraOptions = + let + listenAddress = + with cfg.services.syncthing.web; + (if (enable && public) then "0.0.0.0" else "127.0.0.1"); + in + [ + "--gui-address=${listenAddress}:${builtins.toString cfg.services.syncthing.web.port}" + "--home=${cfg.services.syncthing.home}" + "--no-default-folder" + ]; }; systemd.user.services."syncthing".Unit.RequiresMountsFor = cfg.services.syncthing.home; diff --git a/modules/users/gremlin/default.nix b/modules/users/gremlin/default.nix index dd6c96c..bc0e95a 100644 --- a/modules/users/gremlin/default.nix +++ b/modules/users/gremlin/default.nix @@ -13,16 +13,6 @@ in options = { aux.system.users.gremlin = { enable = lib.mkEnableOption "Enables gremlin user account"; - - services.syncthing = { - enable = lib.mkEnableOption "Enables Syncthing"; - enableTray = lib.mkEnableOption "Enables the Syncthing Tray application"; - home = lib.mkOption { - default = "${config.users.users.gremlin.home}/.config/syncthing"; - type = lib.types.str; - description = "Where to store Syncthing's configuration files"; - }; - }; }; }; @@ -100,28 +90,5 @@ in }; }; }) - - # Enable Syncthing - (lib.mkIf cfg.services.syncthing.enable { - users.users.gremlin.packages = [ pkgs.syncthing ]; - - services.flatpak.packages = lib.mkIf ( - config.aux.system.ui.flatpak.enable && cfg.services.syncthing.enableTray - ) [ "io.github.martchus.syncthingtray" ]; - - home-manager.users.gremlin = { - # Syncthing options - services.syncthing = { - enable = true; - extraOptions = [ - "--gui-address=0.0.0.0:8081" - "--home=${cfg.services.syncthing.home}" - "--no-default-folder" - ]; - }; - - systemd.user.services."syncthing".Unit.RequiresMountsFor = cfg.services.syncthing.home; - }; - }) ]; }