Skip to content

Commit

Permalink
add bcachefs type with support for encryption
Browse files Browse the repository at this point in the history
  • Loading branch information
onny committed May 30, 2023
1 parent 0d27037 commit c82e8a7
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 4 deletions.
4 changes: 2 additions & 2 deletions example/bcachefs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
end = "100%";
part-type = "primary";
content = {
type = "filesystem";
format = "bcachefs";
type = "bcachefs";
keyFile = "/tmp/secret.key";
mountpoint = "/";
};
}
Expand Down
2 changes: 1 addition & 1 deletion lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let

# option for valid contents of devices
deviceType = lib.mkOption {
type = lib.types.nullOr (diskoLib.subType { inherit (diskoLib.types) table btrfs filesystem zfs mdraid luks lvm_pv swap; });
type = lib.types.nullOr (diskoLib.subType { inherit (diskoLib.types) table bcachefs btrfs filesystem zfs mdraid luks lvm_pv swap; });
default = null;
description = "The type of device";
};
Expand Down
79 changes: 79 additions & 0 deletions lib/types/bcachefs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{ config, options, diskoLib, lib, rootMountPoint, ... }:
{
options = {
type = lib.mkOption {
type = lib.types.enum [ "bcachefs" ];
internal = true;
description = "Type";
};
extraArgs = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
description = "Extra arguments";
};
mountOptions = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ "defaults" ];
description = "A list of options to pass to mount.";
};
mountpoint = lib.mkOption {
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname;
default = null;
description = "A path to mount the Bcachefs filesystem to.";
};
_meta = lib.mkOption {
internal = true;
readOnly = true;
type = lib.types.functionTo diskoLib.jsonType;
default = dev:
diskoLib.deepMergeMap (subvol: subvol._meta dev) (lib.attrValues config.subvolumes);
description = "Metadata";
};
_create = diskoLib.mkCreateOption {
inherit config options;
default = { dev }: ''
mkfs.btrfs ${dev} ${toString config.extraArgs}
${lib.concatMapStrings (subvol: subvol._create { inherit dev; }) (lib.attrValues config.subvolumes)}
'';
};
_mount = diskoLib.mkMountOption {
inherit config options;
default = { dev }:
let
subvolMounts = diskoLib.deepMergeMap (subvol: subvol._mount { inherit dev; parent = config.mountpoint; }) (lib.attrValues config.subvolumes);
in
{
fs = subvolMounts.fs // lib.optionalAttrs (config.mountpoint != null) {
${config.mountpoint} = ''
if ! findmnt ${dev} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
mount ${dev} "${rootMountPoint}${config.mountpoint}" \
${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
-o X-mount.mkdir
fi
'';
};
};
};
_config = lib.mkOption {
internal = true;
readOnly = true;
default = dev: [
(lib.optional (config.mountpoint != null) {
fileSystems.${config.mountpoint} = {
device = dev;
fsType = "bcachefs";
options = config.mountOptions;
};
})
];
description = "NixOS configuration";
};
_pkgs = lib.mkOption {
internal = true;
readOnly = true;
type = lib.types.functionTo (lib.types.listOf lib.types.package);
default = pkgs: [ pkgs.bcachefs-tools ];
description = "Packages";
};
};
}
2 changes: 1 addition & 1 deletion lib/types/table.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
description = "Partition type";
};
fs-type = lib.mkOption {
type = lib.types.nullOr (lib.types.enum [ "btrfs" "ext2" "ext3" "ext4" "fat16" "fat32" "hfs" "hfs+" "linux-swap" "ntfs" "reiserfs" "udf" "xfs" ]);
type = lib.types.nullOr (lib.types.enum [ "bcachefs" "btrfs" "ext2" "ext3" "ext4" "fat16" "fat32" "hfs" "hfs+" "linux-swap" "ntfs" "reiserfs" "udf" "xfs" ]);
default = null;
description = "Filesystem type to use";
};
Expand Down

0 comments on commit c82e8a7

Please sign in to comment.