fix: simplify syncthing module
This commit is contained in:
@@ -114,26 +114,7 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
my.syncthing = {
|
my.syncthing.enable = true;
|
||||||
enable = true;
|
|
||||||
deviceNames = [
|
|
||||||
"boox"
|
|
||||||
"astyanax"
|
|
||||||
];
|
|
||||||
folders = {
|
|
||||||
readings = {
|
|
||||||
path = "/home/h/doc/readings";
|
|
||||||
id = "readings";
|
|
||||||
devices = [
|
|
||||||
{
|
|
||||||
device = "boox";
|
|
||||||
type = "receiveonly";
|
|
||||||
}
|
|
||||||
"astyanax"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
networking = {
|
networking = {
|
||||||
# TODO: generate unique hostId on actual host with: head -c 8 /etc/machine-id
|
# TODO: generate unique hostId on actual host with: head -c 8 /etc/machine-id
|
||||||
|
|||||||
@@ -105,33 +105,11 @@ in
|
|||||||
enable = true;
|
enable = true;
|
||||||
harden = true;
|
harden = true;
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
my.syncthing = {
|
|
||||||
enable = true;
|
|
||||||
deviceNames = [
|
|
||||||
"boox"
|
|
||||||
"andromache"
|
|
||||||
];
|
|
||||||
folders = {
|
|
||||||
readings = {
|
|
||||||
path = "/home/h/doc/readings";
|
|
||||||
id = "readings";
|
|
||||||
devices = [
|
|
||||||
{
|
|
||||||
device = "boox";
|
|
||||||
type = "receiveonly";
|
|
||||||
}
|
|
||||||
"andromache"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
services = {
|
|
||||||
locate = {
|
locate = {
|
||||||
enable = true;
|
enable = true;
|
||||||
package = pkgs.plocate;
|
package = pkgs.plocate;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
my.syncthing.enable = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ with lib;
|
|||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.my.syncthing;
|
cfg = config.my.syncthing;
|
||||||
allDevices = import ./devices.nix;
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.my.syncthing = {
|
options.my.syncthing = {
|
||||||
@@ -17,41 +16,11 @@ in
|
|||||||
type = types.str;
|
type = types.str;
|
||||||
default = "h";
|
default = "h";
|
||||||
};
|
};
|
||||||
deviceNames = mkOption {
|
|
||||||
type = types.listOf types.str;
|
|
||||||
default = [ ];
|
|
||||||
};
|
|
||||||
folders = mkOption {
|
|
||||||
type = types.attrsOf (
|
|
||||||
types.submodule {
|
|
||||||
options = {
|
|
||||||
path = mkOption { type = types.path; };
|
|
||||||
id = mkOption { type = types.str; };
|
|
||||||
devices = mkOption {
|
|
||||||
type = types.listOf (
|
|
||||||
types.either types.str (
|
|
||||||
types.submodule {
|
|
||||||
options = {
|
|
||||||
device = mkOption { type = types.str; };
|
|
||||||
type = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
default = "sendreceive";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
|
||||||
default = cfg.deviceNames;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
default = { };
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
users.groups.${cfg.username} = { };
|
users.groups.${cfg.username} = { };
|
||||||
|
users.users.${cfg.username}.extraGroups = [ cfg.username ];
|
||||||
|
|
||||||
services.syncthing = {
|
services.syncthing = {
|
||||||
enable = true;
|
enable = true;
|
||||||
@@ -59,27 +28,6 @@ in
|
|||||||
group = cfg.username;
|
group = cfg.username;
|
||||||
configDir = "/home/${cfg.username}/.local/state/syncthing";
|
configDir = "/home/${cfg.username}/.local/state/syncthing";
|
||||||
openDefaultPorts = true;
|
openDefaultPorts = true;
|
||||||
settings = {
|
|
||||||
options = {
|
|
||||||
localAnnounceEnabled = true;
|
|
||||||
globalAnnounceEnabled = true;
|
|
||||||
relaysEnabled = true;
|
|
||||||
urAccepted = -1;
|
|
||||||
};
|
|
||||||
devices = mapAttrs (name: id: { inherit id; }) (
|
|
||||||
filterAttrs (name: _: elem name cfg.deviceNames) allDevices
|
|
||||||
);
|
|
||||||
folders = mapAttrs (name: folder: {
|
|
||||||
inherit (folder) id path;
|
|
||||||
devices = map (
|
|
||||||
device:
|
|
||||||
if isString device then
|
|
||||||
allDevices.${device}
|
|
||||||
else
|
|
||||||
device // { deviceID = allDevices.${device.device}; }
|
|
||||||
) folder.devices;
|
|
||||||
}) cfg.folders;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user