syncthing: Declarative

I could split this commit in more but I won't.
The first commit in this repository said it would be the last legible
one, and I haven't followed that, so YOLO.
This commit is contained in:
Geoffrey Frogeye 2024-06-23 23:57:03 +02:00
parent b7d56a3118
commit 8edb670486
Signed by: geoffrey
GPG key ID: C72403E7F82E6AD8
20 changed files with 222 additions and 45 deletions

View file

@ -1,6 +1,17 @@
{ lib, config, ... }:
{ pkgs, lib, config, ... }:
let
capitalizeFirstLetter = str: (lib.strings.toUpper (builtins.substring 0 1 str)) + (builtins.substring 1 (builtins.stringLength str) str);
in
{
options.frogeye = {
name = lib.mkOption {
description = "Name of the system";
type = lib.types.str;
};
toplevel = lib.mkOption {
description = "top-level flake";
type = lib.types.attrs;
};
extra = lib.mkEnableOption "Big software";
gaming = lib.mkEnableOption "Games";
polarity = lib.mkOption {
@ -40,11 +51,98 @@
prose = lib.mkEnableOption "Writing stuff";
python = lib.mkEnableOption "Python dev stuff";
};
storageSize = lib.mkOption {
default = "small";
type = lib.types.enum [ "small" "big" "phone" ];
description = "Type of storage for the device. Used to determine which folder to include.";
};
folders = lib.mkOption {
default = { };
description = "Folders used by users";
# Top-level so Syncthing can work for all users. Also there's no real home-manager syncthing module.
type = lib.types.attrsOf (lib.types.submodule ({ config, name, ... }: {
options = {
name = lib.mkOption {
type = lib.types.str;
default = name;
readOnly = true;
internal = true;
description = "Name accessing this entry";
};
enable = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Whether to use this folder.";
};
path = lib.mkOption {
type = lib.types.str;
description = "Path relative to HOME. Prefer French names which has more varied initials, easing navigation.";
};
label = lib.mkOption {
type = lib.types.str;
description = "Friendly name";
default = capitalizeFirstLetter config.path;
};
user = lib.mkOption {
type = lib.types.str;
default = "geoffrey";
description = "User using this directory.";
};
fullPath = lib.mkOption {
type = lib.types.str;
default = "/home/${config.user}/${config.path}";
# Hardcoded due to outside of any user context
description = "Absolute path.";
};
xdgUserDirVariable = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = "XDG_${lib.strings.toUpper name}_DIR";
description = "Name for the XDG user dir variable. If set, will automatically create the directory.";
};
syncthing = lib.mkOption {
default = { };
description = "Syncthing configuration for the folder";
type = lib.types.submodule ({ ... }: {
freeformType = (pkgs.formats.json { }).type;
options = {
enable = lib.mkOption {
type = lib.types.bool;
default = config.enable && config.syncthing.id != null;
description = "Whether to sync.";
};
id = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "Syncthing folder id";
};
};
});
};
versionsMaxDays = lib.mkOption {
type = lib.types.nullOr lib.types.int;
default = 365;
description = "For big systems, how many days of staggered versions should be kept";
};
};
}));
};
hooks.lock = lib.mkOption {
type = lib.types.lines;
default = "";
description = "Bash commands to execute on locking the session.";
};
syncthing = {
id = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "Full syncthing id";
};
name = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = "Geoffrey ${capitalizeFirstLetter config.frogeye.name}";
description = "Syncthing name";
};
};
};
config = {
@ -53,6 +151,7 @@
prose = lib.mkDefault true;
python = lib.mkDefault true;
};
folders.download.path = "Téléchargements";
};
};
}