syncthing: Support remote declarative sync
This commit is contained in:
parent
460ab8938f
commit
aceb44293f
3 changed files with 64 additions and 4 deletions
|
@ -213,6 +213,10 @@
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
modules = [ ./abavorana/standin.nix ];
|
modules = [ ./abavorana/standin.nix ];
|
||||||
};
|
};
|
||||||
|
nixosConfigurations.ludwig = lib.nixosSystem {
|
||||||
|
system = "x86_64-linux";
|
||||||
|
modules = [ ./ludwig/standin.nix ];
|
||||||
|
};
|
||||||
nixosConfigurations.sprinkles = lib.nixosSystem {
|
nixosConfigurations.sprinkles = lib.nixosSystem {
|
||||||
system = "aarch64-linux";
|
system = "aarch64-linux";
|
||||||
modules = [ ./sprinkles/standin.nix ];
|
modules = [ ./sprinkles/standin.nix ];
|
||||||
|
|
10
ludwig/standin.nix
Normal file
10
ludwig/standin.nix
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{ ... }:
|
||||||
|
{
|
||||||
|
config = {
|
||||||
|
frogeye = {
|
||||||
|
name = "ludwig";
|
||||||
|
storageSize = "big";
|
||||||
|
syncthing.name = "Ludwig";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -24,7 +24,9 @@ let
|
||||||
);
|
);
|
||||||
allDevices = nixosDevices;
|
allDevices = nixosDevices;
|
||||||
syncingDevices = builtins.filter (device: device.syncthing.id != null) allDevices;
|
syncingDevices = builtins.filter (device: device.syncthing.id != null) allDevices;
|
||||||
peerDevices = builtins.filter (device: device.name != config.frogeye.name) syncingDevices;
|
peerDevices = builtins.filter (
|
||||||
|
device: device.syncthing.id != config.frogeye.syncthing.id
|
||||||
|
) syncingDevices;
|
||||||
|
|
||||||
# Can't use the module's folders enable option, as it still requests things somehow
|
# Can't use the module's folders enable option, as it still requests things somehow
|
||||||
allFolders = builtins.attrValues config.frogeye.folders;
|
allFolders = builtins.attrValues config.frogeye.folders;
|
||||||
|
@ -34,12 +36,58 @@ let
|
||||||
folder: device:
|
folder: device:
|
||||||
(lib.hasAttrByPath [ folder.name ] device.folders)
|
(lib.hasAttrByPath [ folder.name ] device.folders)
|
||||||
&& device.folders.${folder.name}.syncthing.enable;
|
&& device.folders.${folder.name}.syncthing.enable;
|
||||||
folderDeviceEntry = folder: device: { deviceID = device.syncthing.id; };
|
|
||||||
|
|
||||||
enable = (builtins.length syncedFolders) > 0;
|
enable = (builtins.length syncedFolders) > 0;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
config = {
|
config = {
|
||||||
|
# Allow to export configuration to other systems
|
||||||
|
system.build.syncthingConfig = {
|
||||||
|
folders = lib.trivial.pipe syncedFolders [
|
||||||
|
(builtins.map (folder: {
|
||||||
|
name = folder.name;
|
||||||
|
value = folder;
|
||||||
|
}))
|
||||||
|
builtins.listToAttrs
|
||||||
|
(lib.attrsets.mapAttrs (
|
||||||
|
folderName: folder:
|
||||||
|
(lib.attrsets.filterAttrs (
|
||||||
|
k: v:
|
||||||
|
builtins.elem k [
|
||||||
|
"label"
|
||||||
|
"path"
|
||||||
|
"syncthing"
|
||||||
|
"user"
|
||||||
|
]
|
||||||
|
))
|
||||||
|
folder
|
||||||
|
))
|
||||||
|
];
|
||||||
|
devices = lib.trivial.pipe syncingDevices [
|
||||||
|
(builtins.map (device: {
|
||||||
|
name = device.name;
|
||||||
|
value = device;
|
||||||
|
}))
|
||||||
|
builtins.listToAttrs
|
||||||
|
(lib.attrsets.mapAttrs (
|
||||||
|
deviceName: device:
|
||||||
|
{
|
||||||
|
folders = lib.trivial.pipe device.folders [
|
||||||
|
(lib.attrsets.filterAttrs (folderName: folder: folder.syncthing.enable))
|
||||||
|
(lib.attrsets.mapAttrs (folderName: folder: { syncthing.enable = true; }))
|
||||||
|
];
|
||||||
|
}
|
||||||
|
//
|
||||||
|
(lib.attrsets.filterAttrs (
|
||||||
|
k: v:
|
||||||
|
builtins.elem k [
|
||||||
|
"syncthing"
|
||||||
|
]
|
||||||
|
))
|
||||||
|
device
|
||||||
|
))
|
||||||
|
];
|
||||||
|
};
|
||||||
services.${service} = {
|
services.${service} = {
|
||||||
inherit enable;
|
inherit enable;
|
||||||
openDefaultPorts = true;
|
openDefaultPorts = true;
|
||||||
|
@ -63,8 +111,6 @@ in
|
||||||
value = {
|
value = {
|
||||||
label = "${capitalizeFirstLetter folder.user} ${folder.label}";
|
label = "${capitalizeFirstLetter folder.user} ${folder.label}";
|
||||||
path = "${config.users.users.${folder.user}.home}/${folder.path}";
|
path = "${config.users.users.${folder.user}.home}/${folder.path}";
|
||||||
# Despite further in the code indicating this is possible, it is, actually not
|
|
||||||
# devices = builtins.map (folderDeviceEntry folder) (builtins.filter (folderShouldSyncWith folder) peerDevices);
|
|
||||||
devices = builtins.map (device: device.name) (
|
devices = builtins.map (device: device.name) (
|
||||||
builtins.filter (folderShouldSyncWith folder) peerDevices
|
builtins.filter (folderShouldSyncWith folder) peerDevices
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue