diff --git a/hosts/Hevana/default.nix b/hosts/Hevana/default.nix index 403e83b..f9dd80e 100644 --- a/hosts/Hevana/default.nix +++ b/hosts/Hevana/default.nix @@ -219,6 +219,15 @@ in enable = true; ports = [ config.secrets.hosts.hevana.ssh.port ]; }; + syncthing = { + enable = true; + home = "${services-root}/syncthing/aires"; + user = "aires"; + web = { + enable = true; + public = true; + }; + }; virtualization.host = { enable = true; user = "aires"; @@ -230,18 +239,6 @@ in }; }; - users.aires = { - enable = true; - services = { - syncthing = { - enable = true; - home = "${services-root}/syncthing/aires"; - web = { - enable = true; - public = true; - }; - }; - }; - }; + users.aires.enable = true; }; } diff --git a/hosts/Khanda/default.nix b/hosts/Khanda/default.nix index b03cd3c..4ade509 100644 --- a/hosts/Khanda/default.nix +++ b/hosts/Khanda/default.nix @@ -55,6 +55,12 @@ in onCalendar = "weekly"; user = config.users.users.aires.name; }; + syncthing = { + enable = true; + home = "/home/aires/.config/syncthing"; + user = "aires"; + web.enable = true; + }; virtualization.enable = true; }; @@ -78,12 +84,6 @@ in }; }; - users.aires = { - enable = true; - services.syncthing = { - enable = true; - web.enable = true; - }; - }; + users.aires.enable = true; }; } diff --git a/hosts/Shura/default.nix b/hosts/Shura/default.nix index 68a61c4..e137152 100644 --- a/hosts/Shura/default.nix +++ b/hosts/Shura/default.nix @@ -69,6 +69,12 @@ in url = config.secrets.services.netdata.url; auth.apiKey = config.secrets.services.netdata.apiKey; }; + syncthing = { + enable = true; + home = "/home/aires/.config/syncthing"; + user = "aires"; + web.enable = true; + }; # Install virtual machine management tools virtualization = { enable = true; @@ -101,13 +107,7 @@ in desktops.gnome.enable = true; }; users = { - aires = { - enable = true; - services.syncthing = { - enable = true; - web.enable = true; - }; - }; + aires.enable = true; gremlin.enable = true; }; }; diff --git a/modules/services/syncthing.nix b/modules/services/syncthing.nix new file mode 100644 index 0000000..9c235cf --- /dev/null +++ b/modules/services/syncthing.nix @@ -0,0 +1,54 @@ +# See https://wiki.nixos.org/wiki/Syncthing +{ config, lib, ... }: + +let + cfg = config.aux.system.services.syncthing; +in +{ + options = { + aux.system.services.syncthing = { + enable = lib.mkEnableOption "Enables Syncthing"; + home = lib.mkOption { + default = "/var/lib/syncthing"; + type = lib.types.str; + description = "Where to store Syncthing's configuration files"; + }; + user = lib.mkOption { + type = lib.types.str; + default = "syncthing"; + description = "User account under which Syncthing runs."; + }; + 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."; + }; + }; + }; + + config = lib.mkIf cfg.enable { + # If the web UI is public, open the port in the firewall + networking.firewall.allowedTCPPorts = with cfg.web; lib.mkIf (enable && public) [ port ]; + + services.syncthing = { + enable = true; + user = cfg.user; + group = config.users.users.${cfg.user}.group; + configDir = cfg.home; + guiAddress = + let + listenAddress = with cfg.web; (if (enable && public) then "0.0.0.0" else "127.0.0.1"); + in + "${listenAddress}:${builtins.toString cfg.web.port}"; + }; + + systemd.services.syncthing = { + environment.STNODEFAULTFOLDER = "true"; # Don't create default ~/Sync folder + unitConfig.RequiresMountsFor = cfg.home; + }; + }; +} diff --git a/modules/users/aires/default.nix b/modules/users/aires/default.nix index e35cab6..95e2050 100644 --- a/modules/users/aires/default.nix +++ b/modules/users/aires/default.nix @@ -1,5 +1,4 @@ { - pkgs, lib, config, ... @@ -14,25 +13,6 @@ in aux.system.users.aires = { enable = lib.mkEnableOption "Enables aires user account"; autologin = lib.mkEnableOption "Automatically logs aires in on boot"; - - services.syncthing = { - enable = lib.mkEnableOption "Enables Syncthing"; - enableTray = lib.mkEnableOption "Enables the Syncthing Tray application"; - home = lib.mkOption { - default = "${config.users.users.aires.home}/.config/syncthing"; - 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."; - }; - }; }; }; @@ -129,39 +109,6 @@ in "autovt@tty1".enable = false; }; }) - - # Configure Syncthing - (lib.mkIf cfg.services.syncthing.enable { - users.users.aires.packages = [ pkgs.syncthing ]; - - services.flatpak.packages = lib.mkIf ( - config.aux.system.ui.flatpak.enable && cfg.services.syncthing.enableTray - ) [ "io.github.martchus.syncthingtray" ]; - - # 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 = { - services.syncthing = { - enable = true; - 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; - }; - }) ] ); }