Migrate localsend to clanServices

This commit is contained in:
pinpox
2025-06-04 14:53:04 +02:00
parent e30522cdad
commit ef4caa94e7
9 changed files with 213 additions and 0 deletions

View File

@@ -61,6 +61,7 @@ in
garage = import ./garage nixosTestArgs;
heisenbridge = import ./heisenbridge nixosTestArgs;
mycelium = import ./mycelium nixosTestArgs;
localsend = import ./localsend nixosTestArgs;
}
// lib.optionalAttrs (pkgs.stdenv.hostPlatform.system == "aarch64-linux") {
# for some reason this hangs in an odd place in CI, but it works on my machine ...

View File

@@ -0,0 +1,51 @@
{
pkgs,
nixosLib,
clan-core,
...
}:
nixosLib.runTest (
{ ... }:
{
imports = [
clan-core.modules.nixosVmTest.clanTest
];
hostPkgs = pkgs;
name = "localsend";
clan = {
directory = ./.;
modules."@clan/localsend" = ../../clanServices/localsend/default.nix;
inventory = {
machines.server = { };
instances = {
localsend-test = {
module.name = "@clan/localsend";
roles.default.machines."server".settings = {
displayName = "Test Instance";
ipv4Addr = "192.168.56.2/24";
};
};
};
};
};
nodes = {
server = { };
};
testScript = ''
start_all()
# Check that the localsend wrapper script is available
server.succeed("command -v localsend")
# Verify the 09-zerotier network is configured with the specified IP address
server.succeed("grep -q 'Address=192.168.56.2/24' /etc/systemd/network/09-zerotier.network")
'';
}
)

View File

@@ -0,0 +1,4 @@
{
"publickey": "age1qm0p4vf9jvcnn43s6l4prk8zn6cx0ep9gzvevxecv729xz540v8qa742eg",
"type": "age"
}

View File

@@ -1,3 +1,5 @@
---
description = "Securely sharing files and messages over a local network without internet connectivity."
categories = ["Utility"]
features = [ "inventory", "deprecated" ]
---

View File

@@ -6,6 +6,7 @@
./ergochat/flake-module.nix
./garage/flake-module.nix
./heisenbridge/flake-module.nix
./localsend/flake-module.nix
./mycelium/flake-module.nix
./auto-upgrade/flake-module.nix
./hello-world/flake-module.nix

View File

@@ -0,0 +1,83 @@
{ ... }:
{
_class = "clan.service";
manifest.name = "clan-core/localsend";
manifest.description = "Local network file sharing application";
manifest.categories = [ "Utility" ];
roles.default = {
interface =
{ lib, ... }:
{
options = {
displayName = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "The name that localsend will use to display your instance.";
};
package = lib.mkOption {
type = lib.types.nullOr lib.types.package;
default = null;
defaultText = "pkgs.localsend of the machine";
description = "The localsend package to use.";
};
ipv4Addr = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "192.168.56.2/24";
description = "Optional IPv4 address for ZeroTier network. Only needed until IPv6 multicasting is supported.";
};
};
};
perInstance =
{
settings,
...
}:
{
nixosModule =
{
pkgs,
lib,
...
}:
{
config = {
clan.core.state.localsend.folders = [ "/var/localsend" ];
environment.systemPackages =
let
localsend-ensure-config = pkgs.writers.writePython3Bin "localsend-ensure-config" {
} ./localsend-ensure-config.py;
localsend = pkgs.writeShellScriptBin "localsend" ''
set -xeu
${lib.getExe localsend-ensure-config} ${
lib.optionalString (settings.displayName != null) settings.displayName
}
${if settings.package != null then lib.getExe settings.package else lib.getExe pkgs.localsend}
'';
in
[ localsend ];
networking.firewall.interfaces."zt+".allowedTCPPorts = [ 53317 ];
networking.firewall.interfaces."zt+".allowedUDPPorts = [ 53317 ];
# This is currently needed because there is no ipv6 multicasting support yet
systemd.network.networks = lib.mkIf (settings.ipv4Addr != null) {
"09-zerotier" = {
networkConfig = {
Address = settings.ipv4Addr;
};
};
};
};
};
};
};
}

View File

@@ -0,0 +1,6 @@
{ lib, ... }:
{
clan.modules = {
localsend = lib.modules.importApply ./default.nix { };
};
}

View File

@@ -0,0 +1,64 @@
import json
import sys
from pathlib import Path
def load_json(file_path: Path) -> dict[str, any]:
try:
with file_path.open("r") as file:
return json.load(file)
except FileNotFoundError:
return {}
def save_json(file_path: Path, data: dict[str, any]) -> None:
with file_path.open("w") as file:
json.dump(data, file, indent=4)
def update_json(file_path: Path, updates: dict[str, any]) -> None:
data = load_json(file_path)
data.update(updates)
save_json(file_path, data)
def config_location() -> str:
config_file = "shared_preferences.json"
config_directory = ".local/share/org.localsend.localsend_app"
config_path = Path.home() / Path(config_directory) / Path(config_file)
return config_path
def ensure_config_directory() -> None:
config_directory = Path(config_location()).parent
config_directory.mkdir(parents=True, exist_ok=True)
def load_config() -> dict[str, any]:
return load_json(config_location())
def save_config(data: dict[str, any]) -> None:
save_json(config_location(), data)
def update_username(username: str, data: dict[str, any]) -> dict[str, any]:
data["flutter.ls_alias"] = username
return data
def main(argv: list[str]) -> None:
try:
display_name = argv[1]
except IndexError:
# This is not an error, just don't update the name
print("No display name provided.")
sys.exit(0)
ensure_config_directory()
updated_data = update_username(display_name, load_config())
save_config(updated_data)
if __name__ == "__main__":
main(sys.argv[:2])

View File

@@ -89,6 +89,7 @@ nav:
- reference/clanServices/ergochat.md
- reference/clanServices/garage.md
- reference/clanServices/heisenbridge.md
- reference/clanServices/localsend.md
- reference/clanServices/mycelium.md
- reference/clanServices/hello-world.md
- reference/clanServices/wifi.md