diff --git a/devices/nas/default.nix b/devices/nas/default.nix index fa7f0467..936d219a 100644 --- a/devices/nas/default.nix +++ b/devices/nas/default.nix @@ -64,14 +64,10 @@ inputs: xrdp = { enable = true; hostname = [ "nas.chn.moe" "office.chn.moe" ]; }; groupshare = {}; smartd.enable = true; - beesd = + beesd.instances = { - enable = true; - instances = - { - root = { device = "/"; hashTableSizeMB = 4096; threads = 4; }; - nix = { device = "/nix"; hashTableSizeMB = 128; }; - }; + root = { device = "/"; hashTableSizeMB = 4096; threads = 4; }; + nix = { device = "/nix"; hashTableSizeMB = 128; }; }; frpClient = { diff --git a/devices/pc/default.nix b/devices/pc/default.nix index 56a67bc2..844a47e4 100644 --- a/devices/pc/default.nix +++ b/devices/pc/default.nix @@ -109,7 +109,7 @@ inputs: nix-serve = { enable = true; hostname = "nix-store.chn.moe"; }; smartd.enable = true; misskey.instances.misskey.hostname = "xn--qbtm095lrg0bfka60z.chn.moe"; - beesd = { enable = true; instances.root = { device = "/"; hashTableSizeMB = 4096; threads = 4; }; }; + beesd.instances.root = { device = "/"; hashTableSizeMB = 4096; threads = 4; }; wireguard = { enable = true; diff --git a/devices/surface/default.nix b/devices/surface/default.nix index 4aefd0b6..2cca452c 100644 --- a/devices/surface/default.nix +++ b/devices/surface/default.nix @@ -59,7 +59,7 @@ inputs: publicKey = "j7qEeODVMH31afKUQAmKRGLuqg8Bxd0dIPbo17LHqAo="; wireguardIp = "192.168.83.5"; }; - beesd = { enable = true; instances.root = { device = "/"; hashTableSizeMB = 512; }; }; + beesd.instances.root = { device = "/"; hashTableSizeMB = 512; }; }; bugs = [ "xmunet" ]; }; diff --git a/devices/vps6/default.nix b/devices/vps6/default.nix index ad934b41..87ace37d 100644 --- a/devices/vps6/default.nix +++ b/devices/vps6/default.nix @@ -77,7 +77,7 @@ inputs: listenIp = "74.211.99.69"; lighthouse = true; }; - beesd = { enable = true; instances.root = { device = "/"; hashTableSizeMB = 64; }; }; + beesd.instances.root = { device = "/"; hashTableSizeMB = 64; }; }; }; }; diff --git a/devices/vps7/default.nix b/devices/vps7/default.nix index f1103b42..b015b825 100644 --- a/devices/vps7/default.nix +++ b/devices/vps7/default.nix @@ -52,7 +52,7 @@ inputs: }; xrdp = { enable = true; hostname = [ "vps7.chn.moe" ]; }; vaultwarden.enable = true; - beesd = { enable = true; instances.root = { device = "/"; hashTableSizeMB = 1024; }; }; + beesd.instances.root = { device = "/"; hashTableSizeMB = 1024; }; photoprism.enable = true; nextcloud.enable = true; freshrss.enable = true; diff --git a/devices/xmupc1/default.nix b/devices/xmupc1/default.nix index 3da06b59..ad586901 100644 --- a/devices/xmupc1/default.nix +++ b/devices/xmupc1/default.nix @@ -71,14 +71,10 @@ inputs: xray.client = {}; firewall.trustedInterfaces = [ "virbr0" "waydroid0" ]; smartd.enable = true; - beesd = + beesd.instances = { - enable = true; - instances = - { - root = { device = "/"; hashTableSizeMB = 16384; threads = 4; }; - nix = { device = "/nix"; hashTableSizeMB = 512; }; - }; + root = { device = "/"; hashTableSizeMB = 16384; threads = 4; }; + nix = { device = "/nix"; hashTableSizeMB = 512; }; }; wireguard = { diff --git a/devices/xmupc2/default.nix b/devices/xmupc2/default.nix index f5a00ae8..3f2ce831 100644 --- a/devices/xmupc2/default.nix +++ b/devices/xmupc2/default.nix @@ -65,11 +65,7 @@ inputs: xray.client = {}; firewall.trustedInterfaces = [ "virbr0" "waydroid0" ]; smartd.enable = true; - beesd = - { - enable = true; - instances.root = { device = "/"; hashTableSizeMB = 16384; threads = 4; }; - }; + beesd.instances.root = { device = "/"; hashTableSizeMB = 16384; threads = 4; }; wireguard = { enable = true; diff --git a/modules/services/beesd.nix b/modules/services/beesd.nix index b1e2e024..114133a8 100644 --- a/modules/services/beesd.nix +++ b/modules/services/beesd.nix @@ -1,58 +1,55 @@ inputs: { - options.nixos.services.beesd = let inherit (inputs.lib) mkOption types; in + options.nixos.services.beesd = let inherit (inputs.lib) mkOption types; in mkOption { - enable = mkOption { type = types.bool; default = false; }; - instances = mkOption + type = types.nullOr (types.submodule { options = { - type = types.attrsOf (types.oneOf - [ - types.nonEmptyStr - (types.submodule - { - options = + instances = mkOption + { + type = types.attrsOf (types.oneOf + [ + types.nonEmptyStr + (types.submodule { - device = mkOption { type = types.nonEmptyStr; }; - hashTableSizeMB = mkOption { type = types.ints.unsigned; default = 1024; }; - threads = mkOption { type = types.ints.unsigned; default = 1; }; - };}) - ]); - default = {}; + options = + { + device = mkOption { type = types.nonEmptyStr; }; + hashTableSizeMB = mkOption { type = types.ints.unsigned; default = 1024; }; + threads = mkOption { type = types.ints.unsigned; default = 1; }; + };}) + ]); + default = {}; + }; + };}); + default = null; + }; + config = let inherit (inputs.config.nixos.services) beesd; in inputs.lib.mkIf (beesd != null) + { + services.beesd.filesystems = builtins.listToAttrs (map + (instance: + { + inherit (instance) name; + value = + { + spec = instance.value.device or instance.value; + hashTableSizeMB = instance.value.hashTableSizeMB or 1024; + extraOptions = + [ + "--workaround-btrfs-send" + "--thread-count" "${builtins.toString instance.value.threads or 1}" + "--scan-mode" "3" + ]; + }; + }) + (inputs.localLib.attrsToList beesd.instances)); + systemd.slices.system-beesd.sliceConfig = + { + CPUSchedulingPolicy = "idle"; + IOSchedulingClass = "idle"; + IOSchedulingPriority = 4; + IOAccounting = true; + IOWeight = 1; + Nice = 19; }; }; - config = - let - inherit (inputs.config.nixos.services) beesd; - inherit (inputs.lib) mkIf; - inherit (builtins) map listToAttrs; - inherit (inputs.localLib) attrsToList; - in mkIf beesd.enable - { - services.beesd.filesystems = listToAttrs (map - (instance: - { - inherit (instance) name; - value = - { - spec = instance.value.device or instance.value; - hashTableSizeMB = instance.value.hashTableSizeMB or 1024; - extraOptions = - [ - "--workaround-btrfs-send" - "--thread-count" "${toString instance.value.threads or 1}" - "--scan-mode" "3" - ]; - }; - }) - (attrsToList beesd.instances)); - systemd.slices.system-beesd.sliceConfig = - { - CPUSchedulingPolicy = "idle"; - IOSchedulingClass = "idle"; - IOSchedulingPriority = 4; - IOAccounting = true; - IOWeight = 1; - Nice = 19; - }; - }; }