From 395a25eff1e6647c2bfe6e2348ab15800b4dc8f3 Mon Sep 17 00:00:00 2001 From: Leyla Becker Date: Thu, 13 Mar 2025 02:13:11 -0500 Subject: [PATCH] adopted new syncthing flake --- configurations/syncthing/default.nix | 95 +++++++++++++++++++++++++ flake.lock | 34 +++++++-- flake.nix | 8 +++ modules/nixos-modules/sync.nix | 102 ++++----------------------- util/default.nix | 8 +++ 5 files changed, 154 insertions(+), 93 deletions(-) create mode 100644 configurations/syncthing/default.nix diff --git a/configurations/syncthing/default.nix b/configurations/syncthing/default.nix new file mode 100644 index 0000000..bc557eb --- /dev/null +++ b/configurations/syncthing/default.nix @@ -0,0 +1,95 @@ +{config, ...}: { + folders = { + leyla_documents = { + id = "hvrj0-9bm1p"; + }; + leyla_calendar = { + id = "8oatl-1rv6w"; + }; + leyla_notes = { + id = "dwbuv-zffnf"; + }; + share = { + id = "73ot0-cxmkx"; + }; + }; + devices = { + defiant = { + id = "3R6E6Y4-2F7MF2I-IGB4WE6-A3SQSMV-LIBYSAM-2OXHHU2-KJ6CGIV-QNMCPAR"; + folders = { + leyla_documents = { + folder = config.folders.leyla_documents; + path = "/mnt/sync/leyla/documents"; + }; + leyla_calendar = { + folder = config.folders.leyla_calendar; + path = "/mnt/sync/leyla/calendar"; + }; + leyla_notes = { + folder = config.folders.leyla_notes; + path = "/mnt/sync/leyla/notes"; + }; + share = { + folder = config.folders.share; + path = "/mnt/sync/default/share"; + }; + }; + }; + twilight = { + id = "UDIYL7V-OAZ2BI3-EJRAWFB-GZYVDWR-JNUYW3F-FFQ35MU-XBTGWEF-QD6K6QN"; + folders = { + leyla_documents = { + folder = config.folders.leyla_documents; + path = "/mnt/sync/leyla/documents"; + }; + share = { + folder = config.folders.share; + path = "/mnt/sync/default/share"; + }; + }; + }; + horizon = { + id = "OGPAEU6-5UR56VL-SP7YC4Y-IMVCRTO-XFD4CYN-Z6T5TZO-PFZNAT6-4MKWPQS"; + folders = { + leyla_documents = { + folder = config.folders.leyla_documents; + path = "/mnt/sync/leyla/documents"; + }; + share = { + folder = config.folders.share; + path = "/mnt/sync/default/share"; + }; + }; + }; + coven = { + id = "QGU7NN6-OMXTWVA-YCZ73S5-2O7ECTS-MUCTN4M-YH6WLEL-U4U577I-7PBNCA5"; + folders = { + share = { + folder = config.folders.share; + }; + }; + }; + ceder = { + id = "MGXUJBS-7AENXHB-7YQRNWG-QILKEJD-5462U2E-WAQW4R4-I2TVK5H-SMK6LAA"; + folders = { + share = { + folder = config.folders.share; + }; + leyla_calendar = { + folder = config.folders.leyla_calendar; + }; + leyla_notes = { + folder = config.folders.leyla_notes; + }; + }; + }; + shale = { + id = "AOAXEVD-QJ2IVRA-6G44Q7Q-TGUPXU2-FWWKOBH-DPKWC5N-LBAEHWJ-7EQF4AM"; + folders = { + share = { + folder = config.folders.share; + }; + }; + }; + }; +} diff --git a/flake.lock b/flake.lock index 0ef39bc..11bbff8 100644 --- a/flake.lock +++ b/flake.lock @@ -29,11 +29,11 @@ }, "locked": { "dir": "pkgs/firefox-addons", - "lastModified": 1741786843, - "narHash": "sha256-1m1krwWuROjou56kuILpYZ3imlOgpW2hPqczObinQwQ=", + "lastModified": 1741838604, + "narHash": "sha256-ytHdrfSbbPvla43Ykd61cVkS2JLA8wBEHcnf4yLFP7Y=", "owner": "rycee", "repo": "nur-expressions", - "rev": "51bc10cdd5c2ea8f2cd5adcc587ba0479409312e", + "rev": "e41884886e7798003973f487f37b979ee92f7d99", "type": "gitlab" }, "original": { @@ -214,6 +214,27 @@ "type": "github" } }, + "nix-syncthing": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1741849924, + "narHash": "sha256-5vyb1H6HtW24QVqfI56P4QVQP6vHh1jS9ULwnunCO94=", + "ref": "main", + "rev": "86bcb200c83b6a5d13b3583126b9d8dc6770613a", + "revCount": 6, + "type": "git", + "url": "https://git.jan-leila.com/jan-leila/nix-syncthing" + }, + "original": { + "ref": "main", + "type": "git", + "url": "https://git.jan-leila.com/jan-leila/nix-syncthing" + } + }, "nix-vscode-extensions": { "inputs": { "flake-utils": "flake-utils_3", @@ -222,11 +243,11 @@ ] }, "locked": { - "lastModified": 1741772639, - "narHash": "sha256-u6jSqRGsfm4Af+tUKJsJ346XwJuomL6Qxiu/BZieowU=", + "lastModified": 1741830545, + "narHash": "sha256-SzbDILDATgMCYk2SxPYLCBVdT6mHtlyeYZDn2SZaIuU=", "owner": "nix-community", "repo": "nix-vscode-extensions", - "rev": "2f079586510bc77bac539cf330edaebb9d51e0e0", + "rev": "28318c164b39b70a14851aed7ad0ea7f03ca417e", "type": "github" }, "original": { @@ -276,6 +297,7 @@ "impermanence": "impermanence", "lix-module": "lix-module", "nix-darwin": "nix-darwin", + "nix-syncthing": "nix-syncthing", "nix-vscode-extensions": "nix-vscode-extensions", "nixos-hardware": "nixos-hardware", "nixpkgs": "nixpkgs", diff --git a/flake.nix b/flake.nix index bf9976d..8c64e2b 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,10 @@ }; # common config for syncthing + nix-syncthing = { + url = "git+https://git.jan-leila.com/jan-leila/nix-syncthing?ref=main"; + inputs.nixpkgs.follows = "nixpkgs"; + }; # disk configurations disko = { @@ -73,6 +77,7 @@ self, nixpkgs, sops-nix, + nix-syncthing, home-manager, impermanence, ... @@ -84,6 +89,7 @@ mkNixosSystem = util.mkNixosSystem; mkDarwinSystem = util.mkDarwinSystem; mkHome = util.mkHome; + syncthingConfiguration = util.syncthingConfiguration; installerSystems = { basic = mkNixosInstaller "basic" []; @@ -153,5 +159,7 @@ darwinConfigurations = darwinSystems; homeConfigurations = homeConfigurations; + + syncthingConfiguration = syncthingConfiguration; }; } diff --git a/modules/nixos-modules/sync.nix b/modules/nixos-modules/sync.nix index 516e141..e185781 100644 --- a/modules/nixos-modules/sync.nix +++ b/modules/nixos-modules/sync.nix @@ -1,6 +1,7 @@ { config, lib, + outputs, ... }: let mountDir = "/mnt/sync"; @@ -59,97 +60,24 @@ in { configDir = configDir; overrideDevices = true; overrideFolders = true; - settings = { - devices = { - ceder = { - id = "MGXUJBS-7AENXHB-7YQRNWG-QILKEJD-5462U2E-WAQW4R4-I2TVK5H-SMK6LAA"; - }; - coven = { - id = "QGU7NN6-OMXTWVA-YCZ73S5-2O7ECTS-MUCTN4M-YH6WLEL-U4U577I-7PBNCA5"; - }; - defiant = lib.mkIf (config.networking.hostName != "defiant") { - id = "3R6E6Y4-2F7MF2I-IGB4WE6-A3SQSMV-LIBYSAM-2OXHHU2-KJ6CGIV-QNMCPAR"; - }; - twilight = lib.mkIf (config.networking.hostName != "twilight") { - id = "UDIYL7V-OAZ2BI3-EJRAWFB-GZYVDWR-JNUYW3F-FFQ35MU-XBTGWEF-QD6K6QN"; - }; - horizon = lib.mkIf (config.networking.hostName != "horizon") { - id = "OGPAEU6-5UR56VL-SP7YC4Y-IMVCRTO-XFD4CYN-Z6T5TZO-PFZNAT6-4MKWPQS"; - }; - shale = { - id = "AOAXEVD-QJ2IVRA-6G44Q7Q-TGUPXU2-FWWKOBH-DPKWC5N-LBAEHWJ-7EQF4AM"; - }; - }; - folders = let - ceder = "ceder"; - coven = "coven"; - shale = "shale"; - defiant = lib.mkIf (config.networking.hostName != "defiant") "defiant"; - twilight = lib.mkIf (config.networking.hostName != "twilight") "twilight"; - horizon = lib.mkIf (config.networking.hostName != "horizon") "horizon"; - in - lib.mkMerge [ - config.host.sync.folders.extraFolders - (lib.mkIf config.host.sync.folders.leyla.documents.enable { - "documents" = { - id = "hvrj0-9bm1p"; - path = "${mountDir}/leyla/documents"; - devices = [ - defiant - ceder - coven - twilight - horizon - ]; - }; - }) - (lib.mkIf config.host.sync.folders.share.calendar.enable { - "calendar" = { - id = "8oatl-1rv6w"; - path = "${mountDir}/default/calendar"; - devices = [ - defiant - ceder - shale - ]; - }; - }) - (lib.mkIf config.host.sync.folders.leyla.notes.enable { - "notes" = { - id = "dwbuv-zffnf"; - path = "${mountDir}/leyla/notes"; - devices = [ - defiant - ceder - ]; - }; - }) - (lib.mkIf config.host.sync.folders.share.enable { - "share" = { - id = "73ot0-cxmkx"; - path = "${mountDir}/default/share"; - devices = [ - defiant - ceder - coven - twilight - horizon - shale - ]; - }; - }) - ]; - }; + configuration = outputs.syncthingConfiguration; + deviceName = config.networking.hostName; }; } (lib.mkIf config.host.impermanence.enable { - assertions = [ - { - assertion = config.services.syncthing.configDir == configDir; - message = "syncthing config dir does not match persistence"; - } - ]; + assertions = + [ + { + assertion = config.services.syncthing.configDir == configDir; + message = "syncthing config dir does not match persistence"; + } + ] + ++ lib.attrsets.mapAttrsToList (_: folder: { + assertion = lib.strings.hasPrefix mountDir folder.path; + message = "syncthing folder ${folder.label} is stored at ${folder.path} which not under the persisted path of ${mountDir}"; + }) + config.services.syncthing.folders; environment.persistence = { "/persist/system/root" = { enable = true; diff --git a/util/default.nix b/util/default.nix index cdc0caa..028212c 100644 --- a/util/default.nix +++ b/util/default.nix @@ -7,6 +7,7 @@ home-manager = inputs.home-manager; nix-darwin = inputs.nix-darwin; sops-nix = inputs.sops-nix; + nix-syncthing = inputs.nix-syncthing; disko = inputs.disko; impermanence = inputs.impermanence; lix-module = inputs.lix-module; @@ -73,6 +74,7 @@ in { system-modules ++ [ sops-nix.nixosModules.sops + nix-syncthing.nixosModules.syncthing impermanence.nixosModules.impermanence home-manager.nixosModules.home-manager disko.nixosModules.disko @@ -107,4 +109,10 @@ in { ../configurations/home-manager/${user} ]; }; + + syncthingConfiguration = nix-syncthing.lib.syncthingConfiguration { + modules = [ + (import ../configurations/syncthing) + ]; + }; }