From d6ed16a832461a9fe68c526c7d31c5cb92ecb2c4 Mon Sep 17 00:00:00 2001 From: John Titor <50095635+JohnRTitor@users.noreply.github.com> Date: Sat, 13 Sep 2025 22:15:20 +0530 Subject: [PATCH] nixos/bcachefs: add boot.bcachefs.package This allows configuring the userspace bcachefs package to use. Similar to boot.zfs.package --- nixos/modules/tasks/filesystems/bcachefs.nix | 25 ++++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/nixos/modules/tasks/filesystems/bcachefs.nix b/nixos/modules/tasks/filesystems/bcachefs.nix index 9f0046d49d9c..1afc60b970a1 100644 --- a/nixos/modules/tasks/filesystems/bcachefs.nix +++ b/nixos/modules/tasks/filesystems/bcachefs.nix @@ -7,6 +7,7 @@ }: let + cfg = config.boot.bcachefs; cfgScrub = config.services.bcachefs.autoScrub; bootFs = lib.filterAttrs ( @@ -146,7 +147,7 @@ let unitConfig.DefaultDependencies = false; serviceConfig = { Type = "oneshot"; - ExecCondition = "${pkgs.bcachefs-tools}/bin/bcachefs unlock -c \"${device}\""; + ExecCondition = "${cfg.package}/bin/bcachefs unlock -c \"${device}\""; Restart = "on-failure"; RestartMode = "direct"; # Ideally, this service would lock the key on stop. @@ -155,7 +156,7 @@ let }; script = let - unlock = ''${pkgs.bcachefs-tools}/bin/bcachefs unlock "${device}"''; + unlock = ''${cfg.package}/bin/bcachefs unlock "${device}"''; unlockInteractively = ''${config.boot.initrd.systemd.package}/bin/systemd-ask-password --timeout=0 "enter passphrase for ${name}" | exec ${unlock}''; in if useClevis fs then @@ -196,6 +197,10 @@ let in { + options.boot.bcachefs.package = lib.mkPackageOption pkgs "bcachefs-tools" { } // { + description = "Configured Bcachefs userspace package."; + }; + options.services.bcachefs.autoScrub = { enable = lib.mkEnableOption "regular bcachefs scrub"; @@ -227,11 +232,11 @@ in { inherit assertions; # needed for systemd-remount-fs - system.fsPackages = [ pkgs.bcachefs-tools ]; - services.udev.packages = [ pkgs.bcachefs-tools ]; + system.fsPackages = [ cfg.package ]; + services.udev.packages = [ cfg.package ]; systemd = { - packages = [ pkgs.bcachefs-tools ]; + packages = [ cfg.package ]; services = lib.mapAttrs' (mkUnits "") ( lib.filterAttrs (n: fs: (fs.fsType == "bcachefs") && (!utils.fsNeededForBoot fs)) config.fileSystems ); @@ -253,12 +258,12 @@ in ]; boot.initrd.systemd.extraBin = { # do we need this? boot/systemd.nix:566 & boot/systemd/initrd.nix:357 - "bcachefs" = "${pkgs.bcachefs-tools}/bin/bcachefs"; - "mount.bcachefs" = "${pkgs.bcachefs-tools}/bin/mount.bcachefs"; + "bcachefs" = "${cfg.package}/bin/bcachefs"; + "mount.bcachefs" = "${cfg.package}/bin/mount.bcachefs"; }; boot.initrd.extraUtilsCommands = lib.mkIf (!config.boot.initrd.systemd.enable) '' - copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/bcachefs - copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/mount.bcachefs + copy_bin_and_libs ${cfg.package}/bin/bcachefs + copy_bin_and_libs ${cfg.package}/bin/mount.bcachefs ''; boot.initrd.extraUtilsCommandsTest = lib.mkIf (!config.boot.initrd.systemd.enable) '' $out/bin/bcachefs version @@ -348,7 +353,7 @@ in "sleep.target" ]; - script = "${lib.getExe pkgs.bcachefs-tools} data scrub ${fs}"; + script = "${lib.getExe cfg.package} data scrub ${fs}"; serviceConfig = { Type = "oneshot";