{ 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"; }; }; }; }