add JuiceFS custom mount service configuration

This commit is contained in:
Menno van Leeuwen 2025-03-19 00:53:22 +01:00
parent c2adf02a55
commit 49d0088595
Signed by: vleeuwenmenno
SSH Key Fingerprint: SHA256:OJFmjANpakwD3F2Rsws4GLtbdz1TJ5tkQF0RZmF0TRE
2 changed files with 113 additions and 0 deletions

View File

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

View File

@ -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;
};
};
}