diff --git a/hosts/alto/default.nix b/hosts/alto/default.nix index f3453b7..342eb76 100644 --- a/hosts/alto/default.nix +++ b/hosts/alto/default.nix @@ -47,6 +47,7 @@ in syncthing = { enable = true; isServer = true; + deviceId = "5R2MH7T-Q2ZZS2P-ZMSQ2UJ-B6VBHES-XYLNMZ6-7FYC27L-4P7MGJ2-FY4ITQD"; }; }; } diff --git a/hosts/fern/default.nix b/hosts/fern/default.nix index 76537bb..f1c50a3 100644 --- a/hosts/fern/default.nix +++ b/hosts/fern/default.nix @@ -24,6 +24,9 @@ enable = true; ssh.enable = true; }; - syncthing.enable = true; + syncthing = { + enable = true; + deviceId = "Q4YPD3V-GXZPHSN-PT5X4PU-FBG4GX2-IASBX75-7NYMG75-4EJHBMZ-4WGDDAP"; + }; }; } diff --git a/hosts/north/default.nix b/hosts/north/default.nix index 9e48d1c..644a8d8 100644 --- a/hosts/north/default.nix +++ b/hosts/north/default.nix @@ -21,7 +21,10 @@ enable = true; ssh.enable = true; }; - syncthing.enable = true; + syncthing = { + enable = true; + deviceId = "FAJS5WM-UAWGW2U-FXCGPSP-VAUOTGM-XUKSEES-D66PMCJ-WBODJLV-XTNCRA7"; + }; steam.enable = true; }; diff --git a/modules/system/syncthing.nix b/modules/system/syncthing.nix index 0bb972e..3271f39 100644 --- a/modules/system/syncthing.nix +++ b/modules/system/syncthing.nix @@ -1,4 +1,9 @@ -{ config, lib, ... }: +{ + config, + self, + lib, + ... +}: let cfg = config.myConfig.syncthing; in @@ -6,6 +11,10 @@ in options.myConfig.syncthing = { enable = lib.mkEnableOption ""; isServer = lib.mkEnableOption ""; + deviceId = lib.mkOption { + type = lib.types.nonEmptyStr; + default = ""; + }; }; config = lib.mkIf cfg.enable { @@ -19,20 +28,17 @@ in guiAddress = lib.mkIf cfg.isServer "0.0.0.0:8384"; settings = { - devices = { - alto = { - id = "5R2MH7T-Q2ZZS2P-ZMSQ2UJ-B6VBHES-XYLNMZ6-7FYC27L-4P7MGJ2-FY4ITQD"; - addresses = [ "tcp://alto.${config.networking.domain}:22000" ]; - }; - fern = { - id = "Q4YPD3V-GXZPHSN-PT5X4PU-FBG4GX2-IASBX75-7NYMG75-4EJHBMZ-4WGDDAP"; - addresses = [ "tcp://fern.${config.networking.domain}:22000" ]; - }; - north = { - id = "FAJS5WM-UAWGW2U-FXCGPSP-VAUOTGM-XUKSEES-D66PMCJ-WBODJLV-XTNCRA7"; - addresses = [ "tcp://north.${config.networking.domain}:22000" ]; - }; - }; + # Get the devices and their ids from the configs of the other hosts + devices = + self.nixosConfigurations + |> lib.filterAttrs (name: _: name != config.networking.hostName) + |> lib.filterAttrs (_: value: value.config.myConfig.syncthing.enable) + |> lib.mapAttrs ( + name: value: { + id = value.config.myConfig.syncthing.deviceId; + addresses = [ "tcp://${name}.${value.config.networking.domain}:22000" ]; + } + ); folders = let