nixos-config/system/all/syncthing.nix

186 lines
5.8 KiB
Nix
Raw Normal View History

2019-10-24 02:20:38 +02:00
{ config, lib, pkgs, ... }:
with lib;
{
2019-10-26 13:44:27 +02:00
services.syncthing = {
2019-10-24 02:20:38 +02:00
guiAddress = "${config.networking.hostName}.private:8384";
declarative = {
overrideDevices = true;
devices = let
device = name: id:
{
"${name}" = {
name = name;
id = id;
addresses = [ "tcp://${name}.private:22000" "tcp://${name}.private:21027" ];
};
};
in
(device "workhorse" "AFSAKB6-JLH4QAS-DSRMPI3-6PVCIHF-IIAVLPC-STPNO3Y-YRDU5NW-QD445QI")
// (device "pepe" "SZLXFW3-VTAC7UB-V2Z7CHE-3VZAYPL-6D72AK6-OCDMPZP-G4FPY5P-FL6ZVAG")
// (device "workout" "DZOOAKG-GI2SVOS-QEVMFL7-TRHVTPQ-ADIJEVH-RH5WV3J-6M7MJHC-C53EOAC")
// (device "porani" "6YOIA4E-X52ZD5Z-FPNWPRS-77QIMMU-VDIXVZB-6BPQN7A-FFJDU4W-EXEGFAI")
2019-10-25 03:03:25 +02:00
// (device "sterni" "ZFNNKPD-ZSOAYJQ-VROXXDB-5MD3UTJ-GDCNTSQ-G5POVV3-UZG5HFT-CCAU3AD")
2019-10-24 02:20:38 +02:00
// {
smartphone = {
name = "smartphone";
id = "P6MFODE-PO7CRVB-5RL5AMX-HG4D2CE-C2NC7M4-RYHGX2N-VUU2DWL-C6GVPQN";
addresses = [ "dynamic" ];
};
}
// {
bumba = {
name = "windows-bumba";
id = "JS7PWTO-VKFGBUP-GNFLSWP-MGFJ2KH-HLO2LKW-V3RPCR6-PCB5SQC-42FCKQZ";
addresses = [ "dynamic" ];
};
}
// {
mors = {
name = "lassulus-mors";
id = "ZPRS57K-YK32ROQ-7A6MRAV-VOYXQ3I-CQCXISZ-C5PCV2A-GSFLG3I-K7UGGAH";
addresses = [ "tcp://mors.r:22000" ];
};
};
folders = {
2019-10-25 03:03:25 +02:00
# needs to be on encrypted drives
# -------------------------------
desktop = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
watch = false;
2019-10-25 03:03:25 +02:00
devices = [ "workout" "workhorse" "pepe" "sterni" "porani" ];
2019-10-24 02:20:38 +02:00
};
2019-10-25 03:03:25 +02:00
finance = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
watch = false;
2019-10-25 03:03:25 +02:00
devices = [ "workout" "workhorse" "pepe" "sterni" "porani" ];
2019-10-24 02:20:38 +02:00
};
2019-10-25 03:03:25 +02:00
# no need to be stored on encrypted drives
# ----------------------------------------
book = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-25 03:03:25 +02:00
id = "wwbvs-5lfbh";
2019-10-24 02:20:38 +02:00
watch = false;
2019-10-25 03:03:25 +02:00
devices = [ "workout" "pepe" "sterni" ];
2019-10-24 02:20:38 +02:00
};
2019-10-25 03:03:25 +02:00
lost-fotos = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
watch = false;
2019-10-25 09:55:04 +02:00
devices = [ "workout" "workhorse" "sterni" "porani" ];
2019-10-24 02:20:38 +02:00
};
movies = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
id = "vatmy-c2qf4";
watch = false;
devices = [ "workhorse" "porani" ];
};
porn = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
id = "vatmy-c2qf4";
watch = false;
devices = [ "workhorse" "porani" ];
};
music-library = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
id = "gytmq-r2zrx";
watch = false;
devices = [ "porani" "workout" "workhorse" "pepe" "sterni" ];
};
music-library-free = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
id = "mu9mn-zgvsw";
watch = false;
devices = [ "workout" "workhorse" "mors" ];
};
music-projects = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
id = "acfhu-r4t4f";
watch = false;
devices = [ "workout" "workhorse" "pepe" "sterni" ];
};
podcasts = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
id = "yvzmx-hcomd";
watch = false;
devices = [ "workhorse" "porani" ];
};
samples = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
id = "pcgkj-tjucd";
watch = false;
devices = [ "workout" "workhorse" "sterni" ];
};
series = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
id = "all-series";
watch = false;
devices = [ "workhorse" "porani" ];
};
smartphone-music = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
id = "0vjze-xvs8n";
watch = false;
devices = [ "workout" "smartphone" ];
};
smartphone-fotos = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
id = "e5823_jtbr-photos";
watch = false;
devices = [ "sterni" "workout" "pepe" "smartphone" ];
};
video-material = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
id = "wgkun-fec5h";
watch = false;
devices = [ "workout" "workhorse" ];
};
# one on one
porani-workout = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
devices = [ "porani" "workout" ];
watch = false;
};
porani-pepe = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
devices = [ "porani" "pepe" ];
watch = false;
};
windows-sync = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
id = "hcity-p5ikc";
watch = false;
2019-10-25 08:17:56 +02:00
devices = [ "bumba" "workout" ];
2019-10-24 02:20:38 +02:00
};
workout-pepe = {
2019-10-26 13:44:27 +02:00
enable = lib.mkDefault false;
2019-10-24 02:20:38 +02:00
devices = [ "pepe" "workout" ];
watch = false;
};
};
};
};
# convenience script to know which folder needs to be configured
environment.systemPackages =
let
2019-10-26 13:44:27 +02:00
folders = config.services.syncthing.declarative.folders;
2019-10-24 02:20:38 +02:00
computers = unique (flatten (mapAttrsToList (_: value: value.devices) folders));
isComputerInDeviceList = computer: deviceList: (unique deviceList) == (unique (deviceList ++ [ computer ]));
getFolderNames = computer: naturalSort (builtins.attrNames (filterAttrs (_: folder: isComputerInDeviceList computer folder.devices) folders));
computerMap = foldl (acumulator: computer: acumulator // { "${computer}" = getFolderNames computer; } ) {} computers;
printTemplate = folder: ''${folder}.path = "";'';
in
mapAttrsToList (computer: folders: pkgs.writeShellScriptBin "syncthing.${computer}" ''
cat <<EOF
${concatStringsSep "\n" (map printTemplate folders)}
EOF
'') computerMap;
}