summaryrefslogtreecommitdiff
path: root/rust-src/module.nix
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@linux.dev>2023-01-03 22:31:36 -0500
committerKent Overstreet <kent.overstreet@linux.dev>2023-02-21 01:03:08 -0500
commit28f703cc256fb6ae209aba1d1fe509d603de1735 (patch)
tree220fc0e14cd29a3b56fe18dc8594d7bb4fe66718 /rust-src/module.nix
parentda6a35689518599b381c285cd9505ab8d58f7c73 (diff)
Rust now integrated into bcachefs binary
Rust is now required for building the bcachefs tool, and rust code is now fully integrated with the C codebase - meaning it is possible to call back and forth. The mount helper is now a subcommand, 'mount.bcachefs' is now a small shell wrapper that invokes 'bcachefs mount'. This will make it easier to start rewriting other subcommands in rust, and eventually the whole command line interface. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'rust-src/module.nix')
-rw-r--r--rust-src/module.nix54
1 files changed, 54 insertions, 0 deletions
diff --git a/rust-src/module.nix b/rust-src/module.nix
new file mode 100644
index 00000000..b62aa7dc
--- /dev/null
+++ b/rust-src/module.nix
@@ -0,0 +1,54 @@
+## Mirrors: https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/tasks/filesystems/bcachefs.nix
+## with changes to use flakes and import mount.bcachefs
+{ config, lib, pkgs, utils, ... }:
+
+with lib;
+
+let
+
+ bootFs = filterAttrs (n: fs: (fs.fsType == "bcachefs") && (utils.fsNeededForBoot fs)) config.fileSystems;
+ cfg = config.filesystems.bcachefs;
+in
+
+{
+ options.filesystems.bcachefs.packages.tools = lib.mkOption {
+ description = "Which package to use to link in the bcachefs tools package";
+ default = pkgs.bcachefs.tools;
+ type = lib.types.package;
+ };
+ options.filesystems.bcachefs.packages.mount = lib.mkOption {
+ description = "Which package to use to link in the bcachefs mount package";
+ default = pkgs.bcachefs.mount;
+ type = lib.types.package;
+ };
+ options.filesystems.bcachefs.packages.kernelPackages = lib.mkOption {
+ description = "Which package to use to link in the kernel package to use";
+ default = pkgs.bcachefs.kernelPackages;
+ type = lib.types.attrs;
+
+ };
+
+ config = mkIf (elem "bcachefs" config.boot.supportedFilesystems) (mkMerge [
+ {
+ system.fsPackages = [ cfg.packages.tools cfg.packages.mount ];
+
+ # use kernel package with bcachefs support until it's in mainline
+ boot.kernelPackages = cfg.packages.kernelPackages;
+ }
+
+ (mkIf ((elem "bcachefs" config.boot.initrd.supportedFilesystems) || (bootFs != {})) {
+ # chacha20 and poly1305 are required only for decryption attempts
+ boot.initrd.availableKernelModules = [ "sha256" "chacha20" "poly1305" ];
+ boot.initrd.kernelModules = [ "bcachefs" ];
+
+ boot.initrd.extraUtilsCommands = ''
+ copy_bin_and_libs ${cfg.packages.tools}/bin/bcachefs
+ copy_bin_and_libs ${cfg.packages.mount}/bin/mount.bcachefs
+ '';
+ boot.initrd.extraUtilsCommandsTest = ''
+ $out/bin/bcachefs version
+ $out/bin/mount.bcachefs --version
+ '';
+ })
+ ]);
+}