]> git.sesse.net Git - bcachefs-tools-debian/blob - rust-src/mount/module.nix
split mount into a library crate for rust reuse
[bcachefs-tools-debian] / rust-src / mount / module.nix
1 ## Mirrors: https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/tasks/filesystems/bcachefs.nix
2 ## with changes to use flakes and import mount.bcachefs
3 { config, lib, pkgs, utils, ... }:
4
5 with lib;
6
7 let
8
9         bootFs = filterAttrs (n: fs: (fs.fsType == "bcachefs") && (utils.fsNeededForBoot fs)) config.fileSystems;
10         cfg = config.filesystems.bcachefs;
11 in
12
13 {
14         options.filesystems.bcachefs.packages.tools = lib.mkOption {
15                 description = "Which package to use to link in the bcachefs tools package";
16                 default = pkgs.bcachefs.tools;
17                 type = lib.types.package;
18         };
19         options.filesystems.bcachefs.packages.mount = lib.mkOption {
20                 description = "Which package to use to link in the bcachefs mount package";
21                 default = pkgs.bcachefs.mount;
22                 type = lib.types.package;
23         };
24         options.filesystems.bcachefs.packages.kernelPackages = lib.mkOption {
25                 description = "Which package to use to link in the kernel package to use";
26                 default = pkgs.bcachefs.kernelPackages;
27                 type = lib.types.attrs;
28
29         };
30
31         config = mkIf (elem "bcachefs" config.boot.supportedFilesystems) (mkMerge [
32                 {
33                         system.fsPackages = [ cfg.packages.tools cfg.packages.mount ];
34
35                         # use kernel package with bcachefs support until it's in mainline
36                         boot.kernelPackages = cfg.packages.kernelPackages;
37                 }
38
39                 (mkIf ((elem "bcachefs" config.boot.initrd.supportedFilesystems) || (bootFs != {})) {
40                         # chacha20 and poly1305 are required only for decryption attempts
41                         boot.initrd.availableKernelModules = [ "sha256" "chacha20" "poly1305" ];
42                         boot.initrd.kernelModules = [ "bcachefs" ];
43
44                         boot.initrd.extraUtilsCommands = ''
45                                 copy_bin_and_libs ${cfg.packages.tools}/bin/bcachefs
46                                 copy_bin_and_libs ${cfg.packages.mount}/bin/mount.bcachefs
47                         '';
48                         boot.initrd.extraUtilsCommandsTest = ''
49                                 $out/bin/bcachefs version
50                                 $out/bin/mount.bcachefs --version
51                         '';
52                 })
53         ]);
54 }