From dddd4d640da93cf901b9b5464fbbc7a556980a86 Mon Sep 17 00:00:00 2001 From: Christoph Schmatzler Date: Wed, 13 Aug 2025 21:14:05 +0200 Subject: [PATCH] up --- flake.nix | 14 ++++++++++---- modules/services/syncthing.nix | 20 +++++++++++++------- overlays/syncthing-darwin.nix | 6 +++++- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/flake.nix b/flake.nix index 7edbdc7..ce1513c 100644 --- a/flake.nix +++ b/flake.nix @@ -36,6 +36,13 @@ user = constants.user; darwinHosts = builtins.attrNames (builtins.readDir ./hosts/darwin); nixosHosts = builtins.attrNames (builtins.readDir ./hosts/nixos); + + loadDarwinOverlay = overlayPath: let + overlay = import overlayPath; + module = (overlay null { darwin = {}; }).darwinSyncthingModule; + in { + inherit overlay module; + }; in { systems = [ "x86_64-linux" @@ -45,8 +52,7 @@ flake.darwinConfigurations = inputs.nixpkgs.lib.genAttrs darwinHosts ( hostname: let - syncthingOverlay = import ./overlays/syncthing-darwin.nix; - syncthingModule = (syncthingOverlay null { darwin = {}; }).darwinSyncthingModule; + syncthing = loadDarwinOverlay ./overlays/syncthing-darwin.nix; in inputs.darwin.lib.darwinSystem { system = "aarch64-darwin"; @@ -58,10 +64,10 @@ modules = [ inputs.home-manager.darwinModules.home-manager inputs.nix-homebrew.darwinModules.nix-homebrew - syncthingModule + syncthing.module { - nixpkgs.overlays = [ syncthingOverlay ]; + nixpkgs.overlays = [ syncthing.overlay ]; nix-homebrew = { inherit user; diff --git a/modules/services/syncthing.nix b/modules/services/syncthing.nix index 07db44b..4c0f76c 100644 --- a/modules/services/syncthing.nix +++ b/modules/services/syncthing.nix @@ -5,16 +5,22 @@ ... }: let isDarwin = pkgs.stdenv.isDarwin; - isLinux = pkgs.stdenv.isLinux; - homeDir = if isDarwin then "/Users/${user}" else "/home/${user}"; + + platformConfig = if isDarwin then { + homeDir = "/Users/${user}"; + group = "staff"; + } else { + homeDir = "/home/${user}"; + group = "users"; + }; in { services.syncthing = { enable = true; - openDefaultPorts = isLinux; - dataDir = "${homeDir}/.local/share/syncthing"; - configDir = "${homeDir}/.config/syncthing"; + openDefaultPorts = !isDarwin; + dataDir = "${platformConfig.homeDir}/.local/share/syncthing"; + configDir = "${platformConfig.homeDir}/.config/syncthing"; user = "${user}"; - group = if isDarwin then "staff" else "users"; + group = platformConfig.group; guiAddress = "0.0.0.0:8384"; overrideFolders = true; overrideDevices = true; @@ -26,7 +32,7 @@ in { }; folders = { "Projects" = { - path = "${homeDir}/Projects"; + path = "${platformConfig.homeDir}/Projects"; devices = ["tahani" "jason"]; }; }; diff --git a/overlays/syncthing-darwin.nix b/overlays/syncthing-darwin.nix index 046d2ab..2b1605f 100644 --- a/overlays/syncthing-darwin.nix +++ b/overlays/syncthing-darwin.nix @@ -1,5 +1,6 @@ final: prev: { - darwinSyncthingModule = { config, lib, pkgs, ... }: + darwinModules = prev.darwinModules or {} // { + syncthing = { config, lib, pkgs, ... }: with lib; let cfg = config.services.syncthing; @@ -383,4 +384,7 @@ final: prev: { ''; }; }; + }; + + darwinSyncthingModule = final.darwinModules.syncthing; }