aboutsummaryrefslogtreecommitdiff
path: root/nixos/modules/syncthing.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/modules/syncthing.nix')
-rw-r--r--nixos/modules/syncthing.nix115
1 files changed, 115 insertions, 0 deletions
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
+ };
+ };
+
+}