commit fdb971aee0a3d73d7b5af54101eaf18d3eeea07e
parent e5a90de0ca70c21306ece69807f1d81da4918a30
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 14 Mar 2022 23:25:58 +0100
parent e5a90de0ca70c21306ece69807f1d81da4918a30
Author: Leah (ctucx) <leah@ctu.cx>
Date: Mon, 14 Mar 2022 23:25:58 +0100
syncthing: split configured devices and shares from service configuration
2 files changed, 222 insertions(+), 209 deletions(-)
M
|
214
++-----------------------------------------------------------------------------
A
|
217
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
diff --git a/configurations/services/syncthing.nix b/configurations/services/syncthing.nix @@ -1,83 +1,7 @@ -{ config, lib, ... }: +{ config, pkgs, lib, ... }: let - secrets = import ../../secrets; - devices = { - #laptops/desktops - coladose.id = secrets.syncthing.ids.coladose; - currywurst.id = secrets.syncthing.ids.currywurst; - stasicontainer.id = secrets.syncthing.ids.stasicontainer; -# ludmilla.id = secrets.syncthing.ids.ludmilla; - - #servers - desastro = { - name = "desastro.ctu.cx"; - id = secrets.syncthing.ids.desastro; - }; - lollo = { - name = "lollo.ctu.cx"; - id = secrets.syncthing.ids.lollo; - }; - osterei = { - name = "osterei.ctu.cx"; - id = secrets.syncthing.ids.osterei; - }; - taurus = { - name = "taurus.ctu.cx"; - id = secrets.syncthing.ids.taurus; - }; - }; - - isaDevices = { - isa-x390.id = secrets.syncthing.ids.isa-x390; - isa-p2max.id = secrets.syncthing.ids.isa-p2max; - isa-mbp15.id = secrets.syncthing.ids.isa-mbp15; - isa-mba13.id = secrets.syncthing.ids.isa-mba13; - isa-nuc.id = secrets.syncthing.ids.isa-nuc; - }; - - enabledShares = { - desastro = [ - "ctucx-audiobooks-orig" - "ctucx-music-orig" - "ctucx-media" - "ctucx-windoofs" - ]; - - lollo = [ - "ctucx-audiobooks-orig" - "ctucx-music-orig" - "ctucx-media" - "ctucx-windoofs" - ]; - - - stasicontainer = [ - "ctucx-audiobooks-orig" - "ctucx-music-orig" - ]; - - currywurst = [ - "ctucx-audiobooks-orig" - "ctucx-music-orig" - ]; - }; - - deviceNames = builtins.attrNames (lib.filterAttrs isCurrentHost devices); - isaDeviceNames = builtins.attrNames isaDevices; - shareDeviceNames = share: builtins.attrNames (lib.filterAttrs (n: v: builtins.elem share v) enabledShares); - - filterCurrentHost = devices: lib.remove config.networking.hostName devices; - - isCurrentHost = n: v: n != config.networking.hostName; - isShareEnabled = share: - if builtins.hasAttr config.networking.hostName enabledShares then - (if builtins.elem share enabledShares.${config.networking.hostName} then true else false) - else - false; - - appendDataDirHosts = [ "desastro" "lollo" "taurus" "osterei" ]; - dataDir = "/home/leah" + (if builtins.elem config.networking.hostName appendDataDirHosts then "/syncthing" else ""); + syncthingConfig = import ../syncthing.nix { inherit config; inherit lib; }; in { @@ -103,141 +27,13 @@ in { key = config.age.secrets.syncthing-key.path; cert = config.age.secrets.syncthing-cert.path; - dataDir = "${dataDir}"; + dataDir = syncthingConfig.dataDir; configDir = "/home/leah/.config/syncthing"; - devices = (lib.mkMerge [ (lib.filterAttrs isCurrentHost devices) isaDevices]); - - folders = { - - "${dataDir}/Audiobooks (Originals)" = rec { - enable = isShareEnabled "${id}"; - id = "ctucx-audiobooks-orig"; - label = "Audiobooks (Originals}"; - devices = filterCurrentHost (shareDeviceNames "${id}"); - versioning.type = "trashcan"; - versioning.params = { - cleanoutDays = "3"; - }; - }; - - "${dataDir}/Audiobooks" = { - id = "ctucx-audiobooks"; - label = "Audiobooks"; - devices = deviceNames; - versioning.type = "trashcan"; - versioning.params = { - cleanoutDays = "3"; - }; - }; - - "${dataDir}/Documents" = { - id = "ctucx-documents"; - label = "Documents"; - devices = deviceNames; - versioning.type = "trashcan"; - versioning.params = { - cleanoutDays = "3"; - }; - }; - - "${dataDir}/Music" = { - id = "ctucx-music"; - label = "Music"; - devices = deviceNames; - versioning.type = "trashcan"; - versioning.params = { - cleanoutDays = "3"; - }; - }; - - "${dataDir}/Music (Originals)" = rec { - enable = isShareEnabled "${id}"; - id = "ctucx-music-orig"; - label = "Music (Originals)"; - devices = filterCurrentHost (shareDeviceNames "${id}"); - versioning.type = "trashcan"; - versioning.params = { - cleanoutDays = "3"; - }; - }; - - "${dataDir}/Pictures" = { - id = "ctucx-pictures"; - label = "Pictures"; - devices = deviceNames; - versioning.type = "trashcan"; - versioning.params = { - cleanoutDays = "3"; - }; - }; - - "${dataDir}/Videos" = { - id = "ctucx-videos"; - label = "Videos"; - devices = deviceNames; - versioning.type = "trashcan"; - versioning.params = { - cleanoutDays = "3"; - }; - }; - - "${dataDir}/Media (legacy)" = rec { - enable = isShareEnabled "${id}"; - id = "ctucx-media"; - label = "Media (legacy)"; - devices = filterCurrentHost (shareDeviceNames "${id}"); - versioning.type = "trashcan"; - versioning.params = { - cleanoutDays = "3"; - }; - }; - - "${dataDir}/Windows-Stuff" = rec { - enable = isShareEnabled "${id}"; - id = "ctucx-windoofs"; - label = "Windows-Stuff"; - devices = filterCurrentHost (shareDeviceNames "${id}"); - versioning.type = "trashcan"; - versioning.params = { - cleanoutDays = "3"; - }; - }; - - - - - "${dataDir}/Bahn-Richtlinien" = { - id = "Bahn-Richtlinien"; - label = "Bahn-Richtlinien"; - devices = (lib.mkMerge [ deviceNames isaDeviceNames]); - versioning.type = "trashcan"; - versioning.params = { - cleanoutDays = "3"; - }; - }; - - "${dataDir}/Cutieshare" = { - id = "cutieshare"; - label = "Cutieshare"; - devices = (lib.mkMerge [ deviceNames isaDeviceNames]); - versioning.type = "trashcan"; - versioning.params = { - cleanoutDays = "3"; - }; - }; + devices = syncthingConfig.devices; - "${dataDir}/Wiki" = { - id = "ctucx-wiki"; - label = "Wiki"; - devices = (lib.mkMerge [ deviceNames isaDeviceNames]); - versioning.type = "staggered"; - versioning.params = { - maxAge = "2592000"; - }; - }; + folders = syncthingConfig.folders; - }; }; }; }
diff --git a/configurations/syncthing.nix b/configurations/syncthing.nix @@ -0,0 +1,217 @@ +{ config, lib, ... }: + +let + secrets = import ../secrets; + devices = { + #laptops/desktops + coladose.id = secrets.syncthing.ids.coladose; + currywurst.id = secrets.syncthing.ids.currywurst; + stasicontainer.id = secrets.syncthing.ids.stasicontainer; + + #servers + desastro = { + name = "desastro.ctu.cx"; + id = secrets.syncthing.ids.desastro; + }; + lollo = { + name = "lollo.ctu.cx"; + id = secrets.syncthing.ids.lollo; + }; + osterei = { + name = "osterei.ctu.cx"; + id = secrets.syncthing.ids.osterei; + }; + taurus = { + name = "taurus.ctu.cx"; + id = secrets.syncthing.ids.taurus; + }; + }; + + isaDevices = { + isa-x390.id = secrets.syncthing.ids.isa-x390; + isa-p2max.id = secrets.syncthing.ids.isa-p2max; + isa-mbp15.id = secrets.syncthing.ids.isa-mbp15; + isa-mba13.id = secrets.syncthing.ids.isa-mba13; + isa-nuc.id = secrets.syncthing.ids.isa-nuc; + }; + + enabledShares = { + desastro = [ + "ctucx-audiobooks-orig" + "ctucx-music-orig" + "ctucx-media" + "ctucx-windoofs" + ]; + + lollo = [ + "ctucx-audiobooks-orig" + "ctucx-music-orig" + "ctucx-media" + "ctucx-windoofs" + ]; + + + stasicontainer = [ + "ctucx-audiobooks-orig" + "ctucx-music-orig" + ]; + + currywurst = [ + "ctucx-audiobooks-orig" + "ctucx-music-orig" + ]; + }; + + deviceNames = builtins.attrNames (lib.filterAttrs isCurrentHost devices); + isaDeviceNames = builtins.attrNames isaDevices; + shareDeviceNames = share: builtins.attrNames (lib.filterAttrs (n: v: builtins.elem share v) enabledShares); + + filterCurrentHost = devices: lib.remove config.networking.hostName devices; + + isCurrentHost = n: v: n != config.networking.hostName; + isShareEnabled = share: + if builtins.hasAttr config.networking.hostName enabledShares then + (if builtins.elem share enabledShares.${config.networking.hostName} then true else false) + else + false; + + appendDataDirHosts = [ "desastro" "lollo" "taurus" "osterei" ]; + dataDir = "/home/leah" + (if builtins.elem config.networking.hostName appendDataDirHosts then "/syncthing" else ""); + +in { + + dataDir = dataDir; + + devices = (lib.mkMerge [ (lib.filterAttrs isCurrentHost devices) isaDevices]); + + folders = { + + "${dataDir}/Audiobooks (Originals)" = rec { + enable = isShareEnabled "${id}"; + id = "ctucx-audiobooks-orig"; + label = "Audiobooks (Originals}"; + devices = filterCurrentHost (shareDeviceNames "${id}"); + versioning.type = "trashcan"; + versioning.params = { + cleanoutDays = "3"; + }; + }; + + "${dataDir}/Audiobooks" = { + id = "ctucx-audiobooks"; + label = "Audiobooks"; + devices = deviceNames; + versioning.type = "trashcan"; + versioning.params = { + cleanoutDays = "3"; + }; + }; + + "${dataDir}/Documents" = { + id = "ctucx-documents"; + label = "Documents"; + devices = deviceNames; + versioning.type = "trashcan"; + versioning.params = { + cleanoutDays = "3"; + }; + }; + + "${dataDir}/Music" = { + id = "ctucx-music"; + label = "Music"; + devices = deviceNames; + versioning.type = "trashcan"; + versioning.params = { + cleanoutDays = "3"; + }; + }; + + "${dataDir}/Music (Originals)" = rec { + enable = isShareEnabled "${id}"; + id = "ctucx-music-orig"; + label = "Music (Originals)"; + devices = filterCurrentHost (shareDeviceNames "${id}"); + versioning.type = "trashcan"; + versioning.params = { + cleanoutDays = "3"; + }; + }; + + "${dataDir}/Pictures" = { + id = "ctucx-pictures"; + label = "Pictures"; + devices = deviceNames; + versioning.type = "trashcan"; + versioning.params = { + cleanoutDays = "3"; + }; + }; + + "${dataDir}/Videos" = { + id = "ctucx-videos"; + label = "Videos"; + devices = deviceNames; + versioning.type = "trashcan"; + versioning.params = { + cleanoutDays = "3"; + }; + }; + + "${dataDir}/Media (legacy)" = rec { + enable = isShareEnabled "${id}"; + id = "ctucx-media"; + label = "Media (legacy)"; + devices = filterCurrentHost (shareDeviceNames "${id}"); + versioning.type = "trashcan"; + versioning.params = { + cleanoutDays = "3"; + }; + }; + + "${dataDir}/Windows-Stuff" = rec { + enable = isShareEnabled "${id}"; + id = "ctucx-windoofs"; + label = "Windows-Stuff"; + devices = filterCurrentHost (shareDeviceNames "${id}"); + versioning.type = "trashcan"; + versioning.params = { + cleanoutDays = "3"; + }; + }; + + + + + "${dataDir}/Bahn-Richtlinien" = { + id = "Bahn-Richtlinien"; + label = "Bahn-Richtlinien"; + devices = (lib.mkMerge [ deviceNames isaDeviceNames]); + versioning.type = "trashcan"; + versioning.params = { + cleanoutDays = "3"; + }; + }; + + "${dataDir}/Cutieshare" = { + id = "cutieshare"; + label = "Cutieshare"; + devices = (lib.mkMerge [ deviceNames isaDeviceNames]); + versioning.type = "trashcan"; + versioning.params = { + cleanoutDays = "3"; + }; + }; + + "${dataDir}/Wiki" = { + id = "ctucx-wiki"; + label = "Wiki"; + devices = (lib.mkMerge [ deviceNames isaDeviceNames]); + versioning.type = "staggered"; + versioning.params = { + maxAge = "2592000"; + }; + }; + + }; +}