From 49d00885957cca13f0254e2aa73d38bc54fff196 Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Wed, 19 Mar 2025 00:53:22 +0100 Subject: [PATCH] add JuiceFS custom mount service configuration --- config/nixos/packages/server/default.nix | 9 ++ config/nixos/packages/server/juicefs.nix | 104 +++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 config/nixos/packages/server/juicefs.nix diff --git a/config/nixos/packages/server/default.nix b/config/nixos/packages/server/default.nix index a1f59f2..651c5db 100644 --- a/config/nixos/packages/server/default.nix +++ b/config/nixos/packages/server/default.nix @@ -2,5 +2,14 @@ { # Import all the package modules imports = [ + ./juicefs.nix ]; + + # Enable JuiceFS + services.juicefsCustom = { + enable = true; + redisUrl = "redis://:your-redis-password@localhost:6379/0"; + mountPoint = "/mnt/object_storage"; + cacheDir = "/var/jfsCache"; + }; } diff --git a/config/nixos/packages/server/juicefs.nix b/config/nixos/packages/server/juicefs.nix new file mode 100644 index 0000000..a5f3888 --- /dev/null +++ b/config/nixos/packages/server/juicefs.nix @@ -0,0 +1,104 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.services.juicefsCustom; +in { + options.services.juicefsCustom = { + enable = mkEnableOption "JuiceFS custom mount service"; + + mountPoint = mkOption { + type = types.str; + default = "/mnt/object_storage"; + description = "Directory where JuiceFS should mount the filesystem"; + }; + + cacheDir = mkOption { + type = types.str; + default = "/var/jfsCache"; + description = "Directory for JuiceFS cache"; + }; + + cacheSize = mkOption { + type = types.int; + default = 204800; + description = "Cache size in MiB"; + }; + + redisUrl = mkOption { + type = types.str; + default = "redis://:PASSWORD@localhost:6379/0"; + description = "Redis URL for metadata storage (replace PASSWORD with actual password)"; + }; + + bufferSize = mkOption { + type = types.int; + default = 1024; + description = "Buffer size in MiB"; + }; + + prefetch = mkOption { + type = types.int; + default = 4; + description = "Prefetch size"; + }; + + attrCache = mkOption { + type = types.int; + default = 3; + description = "Attribute cache expiration time in seconds"; + }; + + entryCache = mkOption { + type = types.int; + default = 3; + description = "Entry cache expiration time in seconds"; + }; + + openCache = mkOption { + type = types.int; + default = 3; + description = "Open file cache expiration time in seconds"; + }; + }; + + config = mkIf cfg.enable { + # Install JuiceFS package + environment.systemPackages = [ pkgs.juicefs ]; + + # Create the mount and cache directories + systemd.tmpfiles.rules = [ + "d ${cfg.mountPoint} 0755 root root -" + "d ${cfg.cacheDir} 0755 root root -" + ]; + + # Add the JuiceFS systemd service + systemd.services.juicefs = { + description = "JuiceFS Mount Service"; + wantedBy = [ "multi-user.target" ]; + before = [ "docker.service" ]; + after = [ "network.target" ]; + + serviceConfig = { + Type = "simple"; + ExecStart = "${pkgs.juicefs}/bin/juicefs mount ${cfg.redisUrl} ${cfg.mountPoint} " + + "--cache-dir=${cfg.cacheDir} " + + "--buffer-size=${toString cfg.bufferSize} " + + "--prefetch=${toString cfg.prefetch} " + + "--cache-size=${toString cfg.cacheSize} " + + "--attr-cache=${toString cfg.attrCache} " + + "--entry-cache=${toString cfg.entryCache} " + + "--open-cache=${toString cfg.openCache}"; + Restart = "on-failure"; + }; + }; + + # Setup Redis service if it doesn't exist elsewhere in your config + services.redis = { + enable = true; + bind = "127.0.0.1"; + port = 6379; + }; + }; +}