From 34e4649d28810f28ec8a69d6fe61bae3ef5b2257 Mon Sep 17 00:00:00 2001 From: Steffen Date: Sun, 12 Oct 2025 15:53:51 +0200 Subject: [PATCH] seaweedfs --- configuration.nix | 8 +++ hwaccel.nix | 2 +- seaweedfs-mount.nix | 116 ++++++++++++++++++++++++++++++++++++++++++++ seaweedfs.nix | 21 ++++++++ 4 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 seaweedfs-mount.nix create mode 100644 seaweedfs.nix diff --git a/configuration.nix b/configuration.nix index eb88959..f7e559d 100644 --- a/configuration.nix +++ b/configuration.nix @@ -25,6 +25,7 @@ ./wireguard.nix ./docker.nix ./docker-device-mapper.nix + ./seaweedfs-mount.nix ]; # Use the systemd-boot EFI boot loader. @@ -39,6 +40,12 @@ boot.kernelModules = [ "rbd" "nbd" ]; hardware.bluetooth.enable = true; + hardware.bluetooth.settings = { + General = { + Experimental = true; + }; + }; + networking.hostName = config.vars.hostname; networking.hostId = config.vars.hostid; @@ -101,6 +108,7 @@ zsh zoxide fzf + intel-gpu-tools ]; # Open ports in the firewall. diff --git a/hwaccel.nix b/hwaccel.nix index 09360cb..285d9bf 100644 --- a/hwaccel.nix +++ b/hwaccel.nix @@ -24,4 +24,4 @@ # intel-compute-runtime-legacy1 ]; }; -} \ No newline at end of file +} diff --git a/seaweedfs-mount.nix b/seaweedfs-mount.nix new file mode 100644 index 0000000..41ada19 --- /dev/null +++ b/seaweedfs-mount.nix @@ -0,0 +1,116 @@ +# /etc/nixos/modules/seaweedfs-mount.nix +# +# This module sets up a systemd service to mount a SeaweedFS filer +# via FUSE directly on the NixOS host. + +{ config, pkgs, lib, ... }: + +let + # Use lib.mkOption to create configurable settings for our module. + # This makes it reusable and easy to adjust from configuration.nix. + cfg = config.services.seaweedfs-mount; +in +{ + # Define the options that can be set in configuration.nix + options.services.seaweedfs-mount = { + enable = lib.mkEnableOption "SeaweedFS FUSE mount service"; + + filerAddresses = lib.mkOption { + type = lib.types.listOf lib.types.str; + example = [ "seaweedfs_filer_nix1:8888" "seaweedfs_filer_nix2:8888" ]; + description = "List of filer addresses (hostname:port) to connect to."; + }; + + mountPoint = lib.mkOption { + type = lib.types.path; + default = "/mnt/service/seaweedfs"; + description = "The absolute path where the SeaweedFS volume will be mounted."; + }; + + cacheDir = lib.mkOption { + type = lib.types.path; + default = "/data/seaweedfs/cache"; + description = "Directory for local FUSE cache."; + }; + + volumeDir = lib.mkOption { + type = lib.types.path; + default = "/data/seaweedfs/volume"; + description = "Directory for local volume."; + }; + + user = lib.mkOption { + type = lib.types.str; + default = "root"; + description = "The user to run the mount process as."; + }; + + group = lib.mkOption { + type = lib.types.str; + default = "root"; + description = "The group to run the mount process as."; + }; + }; + + # This part of the module will be activated only if services.seaweedfs-mount.enable = true; + config = lib.mkIf cfg.enable { + + # 1. Ensure the FUSE kernel module is loaded at boot. + boot.kernelModules = [ "fuse" ]; + + # 2. Ensure the seaweedfs package is available in the system path. + environment.systemPackages = [ pkgs.seaweedfs ]; + + # 3. Create the necessary directories before the service starts. + systemd.tmpfiles.rules = [ + "d ${cfg.mountPoint} 0755 ${cfg.user} ${cfg.group} -" + "d ${cfg.cacheDir} 0755 ${cfg.user} ${cfg.group} -" + "d ${cfg.volumeDir} 0755 ${cfg.user} ${cfg.group} -" + ]; + + # 4. Define the systemd service itself. + systemd.services.seaweedfs-mount = { + description = "SeaweedFS FUSE Mount Service"; + + # Start after the network is fully available. + wantedBy = [ "multi-user.target" ]; + after = [ "network-online.target" ]; + wants = [ "network-online.target" ]; + + # Service configuration details. + serviceConfig = { + # The user and group to run the command as. + User = cfg.user; + Group = cfg.group; + + # The core command to start the mount process. + # We build the -filer string by joining the list of addresses with commas. + ExecStart = '' + ${pkgs.seaweedfs}/bin/weed mount \ + -dir=${cfg.mountPoint} \ + -cacheDir=${cfg.cacheDir} \ + -filer=${lib.concatStringsSep "," cfg.filerAddresses} \ + -allowOthers=true \ + -map.uid="1000:0" \ + -map.gid="1000:0" \ + -dirAutoCreate \ + -cacheCapacityMB=15000 \ + -filer.path=/ + ''; + + # Command to cleanly unmount on service stop. + ExecStop = "${pkgs.util-linux}/bin/umount ${cfg.mountPoint}"; + + # *** This is the key part for your request *** + # Always restart the service if it fails. + Restart = "always"; + # Wait 10 seconds before attempting to restart. + RestartSec = "10s"; + + # Required for FUSE mounts to work correctly under systemd. + Type = "simple"; + KillMode = "process"; + }; + }; + }; +} \ No newline at end of file diff --git a/seaweedfs.nix b/seaweedfs.nix new file mode 100644 index 0000000..d7db9e1 --- /dev/null +++ b/seaweedfs.nix @@ -0,0 +1,21 @@ +{ config, pkgs, ... }: { + + # Enable and configure the SeaweedFS mount + services.seaweedfs-mount = { + enable = true; + filerAddresses = [ + "filer_nix1:8888" + "filer_nix2:8888" + "filer_nix3:8888" + "filer_nixnas:8888" + ]; + mountPoint = "/mnt/service/seaweedfs"; + }; + + networking.extraHosts = '' + 192.168.178.5 filer_nix1 + 192.168.178.6 filer_nix2 + 192.168.178.7 filer_nix3 + 192.168.178.8 filer_nixnas + ''; +} \ No newline at end of file