-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add bcachefs type with support for encryption
- Loading branch information
Showing
4 changed files
with
83 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters