From 905c4e73b244b3afa563078edef8631ce6f588a1 Mon Sep 17 00:00:00 2001 From: Leyla Becker Date: Mon, 30 Dec 2024 20:05:52 -0600 Subject: [PATCH] added syncthing --- README.md | 5 +- .../nixos/horizon/configuration.nix | 10 +++ modules/nixos-modules/default.nix | 1 + modules/nixos-modules/sync.nix | 87 +++++++++++++++++++ modules/nixos-modules/users.nix | 18 ++++ 5 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 modules/nixos-modules/sync.nix diff --git a/README.md b/README.md index 2097d8c..2f7b5df 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ | `emergent` | Desktop Computer | Eve | Desktop | | `threshold` | Laptop | Eve | Laptop | | `wolfram` | Steam Deck | House | Handheld | +| `ceder` | A5 Tablet (not using nix) | Leyla | Tablet | +| `skate` | A4 Tablet (not using nix) | Leyla | Tablet | # Tooling ## Rebuilding @@ -57,5 +59,4 @@ - tail scale clients - wake on LAN - ISO target that contains authorized keys for nixos-anywhere https://github.com/diegofariasm/yggdrasil/blob/4acc43ebc7bcbf2e41376d14268e382007e94d78/hosts/bootstrap/default.nix -- Immich -- Syncthing declarative set up for devices https://nixos.wiki/wiki/Syncthing \ No newline at end of file +- Immich \ No newline at end of file diff --git a/configurations/nixos/horizon/configuration.nix b/configurations/nixos/horizon/configuration.nix index 787df3d..bc96142 100644 --- a/configurations/nixos/horizon/configuration.nix +++ b/configurations/nixos/horizon/configuration.nix @@ -19,6 +19,16 @@ ester.isDesktopUser = true; eve.isDesktopUser = true; }; + sync = { + enable = true; + folders = { + leyla = { + documents.enable = true; + calendar.enable = true; + notes.enable = true; + }; + }; + }; }; environment.systemPackages = [ diff --git a/modules/nixos-modules/default.nix b/modules/nixos-modules/default.nix index 41e0619..63b2757 100644 --- a/modules/nixos-modules/default.nix +++ b/modules/nixos-modules/default.nix @@ -8,6 +8,7 @@ ./desktop.nix ./ssh.nix ./i18n.nix + ./sync.nix ./impermanence.nix ./disko.nix ./server diff --git a/modules/nixos-modules/sync.nix b/modules/nixos-modules/sync.nix new file mode 100644 index 0000000..532038e --- /dev/null +++ b/modules/nixos-modules/sync.nix @@ -0,0 +1,87 @@ +{ + config, + lib, + ... +}: let + mountDir = "/mnt/sync"; +in { + options.host.sync = { + enable = lib.mkEnableOption "should sync thing be enabled on this device"; + folders = { + leyla = { + documents = { + enable = lib.mkEnableOption "should the documents folder be synced"; + }; + calendar = { + enable = lib.mkEnableOption "should the calendar folder be synced"; + }; + notes = { + enable = lib.mkEnableOption "should the notes folder by synced"; + }; + }; + extraFolders = lib.mkOption { + type = lib.types.attrsOf (lib.types.submodule ({...}: { + options = { + path = lib.mkOption { + type = lib.types.str; + }; + devices = lib.mkOption { + type = lib.types.listof lib.types.str; + }; + }; + })); + default = {}; + }; + }; + }; + + config = { + systemd = lib.mkIf config.services.syncthing.enable { + tmpfiles.rules = [ + "d ${mountDir} 755 syncthing syncthing -" + "d ${config.services.syncthing.dataDir} 755 syncthing syncthing -" + "d ${config.services.syncthing.configDir} 755 syncthing syncthing -" + ]; + }; + services.syncthing = { + enable = config.host.sync.enable; + user = "syncthing"; + group = "syncthing"; + dataDir = "${mountDir}/default"; + configDir = "/etc/syncthing"; + overrideDevices = true; + overrideFolders = true; + settings = { + devices = { + ceder = { + id = "MGXUJBS-7AENXHB-7YQRNWG-QILKEJD-5462U2E-WAQW4R4-I2TVK5H-SMK6LAA"; + }; + }; + folders = lib.mkMerge [ + config.host.sync.folders.extraFolders + (lib.mkIf config.host.sync.folders.leyla.documents.enable { + "documents" = { + id = "hvrj0-9bm1p"; + path = "/mnt/sync/leyla/documents"; + devices = ["ceder"]; + }; + }) + (lib.mkIf config.host.sync.folders.leyla.calendar.enable { + "calendar" = { + id = "8oatl-1rv6w"; + path = "/mnt/sync/leyla/calendar"; + devices = ["ceder"]; + }; + }) + (lib.mkIf config.host.sync.folders.leyla.notes.enable { + "notes" = { + id = "dwbuv-zffnf"; + path = "/mnt/sync/leyla/notes"; + devices = ["ceder"]; + }; + }) + ]; + }; + }; + }; +} diff --git a/modules/nixos-modules/users.nix b/modules/nixos-modules/users.nix index e2a8074..af7dcb2 100644 --- a/modules/nixos-modules/users.nix +++ b/modules/nixos-modules/users.nix @@ -22,6 +22,7 @@ hass = 2004; headscale = 2005; nextcloud = 2006; + syncthing = 2007; }; gids = { @@ -36,6 +37,7 @@ hass = 2004; headscale = 2005; nextcloud = 2006; + syncthing = 2007; }; users = config.users.users; @@ -160,6 +162,12 @@ in { isSystemUser = true; group = config.users.users.nextcloud.name; }; + + syncthing = { + uid = lib.mkForce uids.syncthing; + isSystemUser = true; + group = config.users.users.syncthing.name; + }; }; groups = { @@ -250,6 +258,16 @@ in { # leyla ]; }; + + syncthing = { + gid = lib.mkForce gids.syncthing; + members = [ + users.syncthing.name + leyla + ester + eve + ]; + }; }; }; }