nixos/bcachefs: add boot.bcachefs.package (#442667)

authored by

Masum Reza and committed by
GitHub
85068ca3 57ae4042

+15 -10
+15 -10
nixos/modules/tasks/filesystems/bcachefs.nix
··· 7 }: 8 9 let 10 cfgScrub = config.services.bcachefs.autoScrub; 11 12 bootFs = lib.filterAttrs ( ··· 146 unitConfig.DefaultDependencies = false; 147 serviceConfig = { 148 Type = "oneshot"; 149 - ExecCondition = "${pkgs.bcachefs-tools}/bin/bcachefs unlock -c \"${device}\""; 150 Restart = "on-failure"; 151 RestartMode = "direct"; 152 # Ideally, this service would lock the key on stop. ··· 155 }; 156 script = 157 let 158 - unlock = ''${pkgs.bcachefs-tools}/bin/bcachefs unlock "${device}"''; 159 unlockInteractively = ''${config.boot.initrd.systemd.package}/bin/systemd-ask-password --timeout=0 "enter passphrase for ${name}" | exec ${unlock}''; 160 in 161 if useClevis fs then ··· 196 in 197 198 { 199 options.services.bcachefs.autoScrub = { 200 enable = lib.mkEnableOption "regular bcachefs scrub"; 201 ··· 227 { 228 inherit assertions; 229 # needed for systemd-remount-fs 230 - system.fsPackages = [ pkgs.bcachefs-tools ]; 231 - services.udev.packages = [ pkgs.bcachefs-tools ]; 232 233 systemd = { 234 - packages = [ pkgs.bcachefs-tools ]; 235 services = lib.mapAttrs' (mkUnits "") ( 236 lib.filterAttrs (n: fs: (fs.fsType == "bcachefs") && (!utils.fsNeededForBoot fs)) config.fileSystems 237 ); ··· 253 ]; 254 boot.initrd.systemd.extraBin = { 255 # do we need this? boot/systemd.nix:566 & boot/systemd/initrd.nix:357 256 - "bcachefs" = "${pkgs.bcachefs-tools}/bin/bcachefs"; 257 - "mount.bcachefs" = "${pkgs.bcachefs-tools}/bin/mount.bcachefs"; 258 }; 259 boot.initrd.extraUtilsCommands = lib.mkIf (!config.boot.initrd.systemd.enable) '' 260 - copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/bcachefs 261 - copy_bin_and_libs ${pkgs.bcachefs-tools}/bin/mount.bcachefs 262 ''; 263 boot.initrd.extraUtilsCommandsTest = lib.mkIf (!config.boot.initrd.systemd.enable) '' 264 $out/bin/bcachefs version ··· 348 "sleep.target" 349 ]; 350 351 - script = "${lib.getExe pkgs.bcachefs-tools} data scrub ${fs}"; 352 353 serviceConfig = { 354 Type = "oneshot";
··· 7 }: 8 9 let 10 + cfg = config.boot.bcachefs; 11 cfgScrub = config.services.bcachefs.autoScrub; 12 13 bootFs = lib.filterAttrs ( ··· 147 unitConfig.DefaultDependencies = false; 148 serviceConfig = { 149 Type = "oneshot"; 150 + ExecCondition = "${cfg.package}/bin/bcachefs unlock -c \"${device}\""; 151 Restart = "on-failure"; 152 RestartMode = "direct"; 153 # Ideally, this service would lock the key on stop. ··· 156 }; 157 script = 158 let 159 + unlock = ''${cfg.package}/bin/bcachefs unlock "${device}"''; 160 unlockInteractively = ''${config.boot.initrd.systemd.package}/bin/systemd-ask-password --timeout=0 "enter passphrase for ${name}" | exec ${unlock}''; 161 in 162 if useClevis fs then ··· 197 in 198 199 { 200 + options.boot.bcachefs.package = lib.mkPackageOption pkgs "bcachefs-tools" { } // { 201 + description = "Configured Bcachefs userspace package."; 202 + }; 203 + 204 options.services.bcachefs.autoScrub = { 205 enable = lib.mkEnableOption "regular bcachefs scrub"; 206 ··· 232 { 233 inherit assertions; 234 # needed for systemd-remount-fs 235 + system.fsPackages = [ cfg.package ]; 236 + services.udev.packages = [ cfg.package ]; 237 238 systemd = { 239 + packages = [ cfg.package ]; 240 services = lib.mapAttrs' (mkUnits "") ( 241 lib.filterAttrs (n: fs: (fs.fsType == "bcachefs") && (!utils.fsNeededForBoot fs)) config.fileSystems 242 ); ··· 258 ]; 259 boot.initrd.systemd.extraBin = { 260 # do we need this? boot/systemd.nix:566 & boot/systemd/initrd.nix:357 261 + "bcachefs" = "${cfg.package}/bin/bcachefs"; 262 + "mount.bcachefs" = "${cfg.package}/bin/mount.bcachefs"; 263 }; 264 boot.initrd.extraUtilsCommands = lib.mkIf (!config.boot.initrd.systemd.enable) '' 265 + copy_bin_and_libs ${cfg.package}/bin/bcachefs 266 + copy_bin_and_libs ${cfg.package}/bin/mount.bcachefs 267 ''; 268 boot.initrd.extraUtilsCommandsTest = lib.mkIf (!config.boot.initrd.systemd.enable) '' 269 $out/bin/bcachefs version ··· 353 "sleep.target" 354 ]; 355 356 + script = "${lib.getExe cfg.package} data scrub ${fs}"; 357 358 serviceConfig = { 359 Type = "oneshot";