From 93b0545d11bf8c7f065203f7f3eaf1d0e3730dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Mon, 21 Feb 2022 21:54:09 +0100 Subject: Add initial version --- nixos/modules/syncthing.nix | 115 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 nixos/modules/syncthing.nix (limited to 'nixos/modules/syncthing.nix') diff --git a/nixos/modules/syncthing.nix b/nixos/modules/syncthing.nix new file mode 100644 index 0000000..44c1ac1 --- /dev/null +++ b/nixos/modules/syncthing.nix @@ -0,0 +1,115 @@ +{ config, lib, pkgs, ... }: + +with builtins; +with lib; + +let + + cnf = config.cynerd.syncthing; + hostName = config.networking.hostName; + allDevices = [ + "albert" "binky" "errol" "lipwig" "ridcully" "susan" "spt-omnia" + ]; + mediaDevices = [ + "lipwig" "binky" "errol" "ridcully" "spt-omnia" + ]; + bigStorageDevices = [ + "errol" "ridcully" "spt-omnia" + ]; + filterDevice = folders: filterAttrs (n: v: any (d: d == hostName) v.devices) folders; + +in { + + options = { + cynerd.syncthing = { + + enable = mkOption { + type = types.bool; + default = false; + description = "My personal Syncthing configuration"; + }; + + baseDir = mkOption { + type = types.str; + default = "/home/cynerd"; + description = "Base directory for all folders being synced."; + }; + + }; + }; + + config = mkIf cnf.enable { + services.syncthing = { + enable = any (n: n == hostName) allDevices; + user = mkDefault "cynerd"; + key = "/run/secrets/syncthing/key.pem"; + cert = "/run/secrets/syncthing/cert.pem"; + + openDefaultPorts = true; + + overrideFolders = true; + folders = filterDevice { + "${cnf.baseDir}/documents" = { + label = "Documents"; + id = "documents"; + devices = allDevices; + ignorePerms = false; + }; + "${cnf.baseDir}/notes" = { + label = "Notes"; + id = "notes"; + devices = allDevices; + ignorePerms = false; + }; + "${cnf.baseDir}/projects" = { + label = "Projects"; + id = "projects"; + devices = allDevices; + ignorePerms = false; + }; + "${cnf.baseDir}/pictures" = { + label = "Pictures"; + id = "pictures"; + devices = mediaDevices; + ignorePerms = false; + }; + # TODO phone-photos + "${cnf.baseDir}/music/primary" = { + label = "Music-primary"; + id = "music-primary"; + devices = mediaDevices; + ignorePerms = false; + }; + "${cnf.baseDir}/music/secondary" = { + label = "Music-secondary"; + id = "music-secondary"; + devices = bigStorageDevices; + ignorePerms = false; + }; + "${cnf.baseDir}/music/flac" = { + label = "Music-flac"; + id = "music-flac"; + devices = bigStorageDevices; + ignorePerms = false; + }; + "${cnf.baseDir}/video" = { + label = "Video"; + id = "video"; + devices = bigStorageDevices; + ignorePerms = false; + }; + }; + + overrideDevices = true; + devices = recursiveUpdate + (genAttrs allDevices (name: { + id = config.secrets.syncthingIDs."${name}"; + })) + { + lipwig.addresses = ["tcp://cynerd.cz"]; + }; + # TODO phone + }; + }; + +} -- cgit v1.2.3