organized into folders
This commit is contained in:
parent
8a8fe8cfc6
commit
84c5dd7422
7 changed files with 5 additions and 9 deletions
3
lib/base-module.nix
Normal file
3
lib/base-module.nix
Normal file
|
@ -0,0 +1,3 @@
|
|||
config: {
|
||||
options = (import ./configuration-type.nix) config;
|
||||
}
|
120
lib/configuration-type.nix
Normal file
120
lib/configuration-type.nix
Normal file
|
@ -0,0 +1,120 @@
|
|||
{lib, ...}: let
|
||||
folderType = lib.types.submodule ({name, ...}: {
|
||||
options = {
|
||||
id = lib.mkOption {
|
||||
type = lib.types.string;
|
||||
};
|
||||
label = lib.mkOption {
|
||||
type = lib.types.string;
|
||||
default = name;
|
||||
};
|
||||
};
|
||||
});
|
||||
in {
|
||||
folders = lib.mkOption {
|
||||
type = lib.types.attrsOf folderType;
|
||||
default = {};
|
||||
};
|
||||
devices = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule ({name, ...}: {
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
type = lib.types.string;
|
||||
default = name;
|
||||
};
|
||||
id = lib.mkOption {
|
||||
type = lib.types.string;
|
||||
};
|
||||
folders = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule (
|
||||
{config, ...}: {
|
||||
options = {
|
||||
folder = lib.mkOption {
|
||||
type = folderType;
|
||||
};
|
||||
path = lib.mkOption {
|
||||
type = lib.types.string;
|
||||
};
|
||||
type = lib.mkOption {
|
||||
type = lib.types.enum ["sendreceive" "sendonly" "receiveonly" "receiveencrypted"];
|
||||
default = "sendreceive";
|
||||
};
|
||||
versioning = {
|
||||
simple = {
|
||||
enable = lib.mkEnableOption "should this folder use simple versioning";
|
||||
keep = lib.mkOption {
|
||||
type = lib.types.string;
|
||||
default = "10";
|
||||
};
|
||||
};
|
||||
trashcan = {
|
||||
enable = lib.mkEnableOption "should this folder use trashcan versioning";
|
||||
cleanoutDays = lib.mkOption {
|
||||
type = lib.types.string;
|
||||
default = "1000";
|
||||
};
|
||||
};
|
||||
staggered = {
|
||||
enable = lib.mkEnableOption "should this folder use staggard versioning";
|
||||
cleanInterval = lib.mkOption {
|
||||
type = lib.types.string;
|
||||
default = "3600";
|
||||
};
|
||||
maxAge = lib.mkOption {
|
||||
type = lib.types.string;
|
||||
default = "31536000";
|
||||
};
|
||||
};
|
||||
external = {
|
||||
enable = lib.mkEnableOption "should this folder use external versioning";
|
||||
};
|
||||
};
|
||||
};
|
||||
# TODO: figure out how to make assertions for submodules
|
||||
# config = {
|
||||
# assertions =
|
||||
# (lib.lists.optionals config.versioning.simple.enable [
|
||||
# {
|
||||
# assertion = !config.versioning.trashcan.enable;
|
||||
# message = "Can not use both simple and trashcan versioning at the same time.";
|
||||
# }
|
||||
# {
|
||||
# assertion = !config.versioning.staggered.enable;
|
||||
# message = "Can not use both simple and staggered versioning at the same time.";
|
||||
# }
|
||||
# {
|
||||
# assertion = !config.versioning.external.enable;
|
||||
# message = "Can not use both simple and external versioning at the same time.";
|
||||
# }
|
||||
# ])
|
||||
# ++ (lib.lists.optionals config.versioning.trashcan.enable [
|
||||
# {
|
||||
# assertion = !config.versioning.staggered.enable;
|
||||
# message = "Can not use both trashcan and staggered versioning at the same time.";
|
||||
# }
|
||||
# {
|
||||
# assertion = !config.versioning.external.enable;
|
||||
# message = "Can not use both trashcan and external versioning at the same time.";
|
||||
# }
|
||||
# ])
|
||||
# ++ (lib.lists.optionals config.versioning.staggered.enable [
|
||||
# {
|
||||
# assertion = !config.versioning.external.enable;
|
||||
# message = "Can not use both staggered and external versioning at the same time.";
|
||||
# }
|
||||
# ])
|
||||
# ++ [
|
||||
# {
|
||||
# assertion = !config.versioning.external.enable;
|
||||
# message = "External versioning currently not implemented.";
|
||||
# }
|
||||
# ];
|
||||
# };
|
||||
}
|
||||
));
|
||||
};
|
||||
};
|
||||
}));
|
||||
default = {};
|
||||
};
|
||||
}
|
9
lib/eval-config.nix
Normal file
9
lib/eval-config.nix
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
lib,
|
||||
modules,
|
||||
}: let
|
||||
result = lib.evalModules {
|
||||
inherit modules;
|
||||
};
|
||||
in
|
||||
result.config
|
43
lib/nixos-module.nix
Normal file
43
lib/nixos-module.nix
Normal file
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
} @ input: {
|
||||
options = {
|
||||
services.syncthing = {
|
||||
configuration = (import ./configuration-type.nix) input;
|
||||
deviceName = lib.mkOption {
|
||||
type = lib.types.string;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
services.syncthing.settings = {
|
||||
devices =
|
||||
lib.attrsets.mapAttrs (name: deviceConfig: {
|
||||
id = deviceConfig.id;
|
||||
})
|
||||
config.services.syncthing.configuration.devices;
|
||||
folders =
|
||||
lib.attrsets.mapAttrs (folderName: folder: {
|
||||
id = folder.folder.id;
|
||||
label = folder.folder.label;
|
||||
path = folder.path;
|
||||
devices = lib.attrsets.mapAttrsToList (_: device: device.name) (
|
||||
lib.attrsets.filterAttrs (
|
||||
deviceName: device:
|
||||
lib.lists.any
|
||||
(
|
||||
deviceFolder: deviceFolder.folder.id == folder.folder.id
|
||||
) (
|
||||
lib.attrsets.mapAttrsToList (_: deviceFolder: deviceFolder) device.folders
|
||||
)
|
||||
)
|
||||
config.services.syncthing.configuration.devices
|
||||
);
|
||||
})
|
||||
config.services.syncthing.configuration.devices.${config.services.syncthing.deviceName}.folders;
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue