-
-
Notifications
You must be signed in to change notification settings - Fork 220
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
5 changed files
with
95 additions
and
6 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
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,89 @@ | ||
{ config, options, diskoLib, lib, rootMountPoint, parent, device, ... }: | ||
{ | ||
options = { | ||
type = lib.mkOption { | ||
type = lib.types.enum [ "bcachefs" ]; | ||
internal = true; | ||
description = "Type"; | ||
}; | ||
device = lib.mkOption { | ||
type = lib.types.str; | ||
default = device; | ||
description = "Device to use"; | ||
}; | ||
extraArgs = lib.mkOption { | ||
type = lib.types.listOf lib.types.str; | ||
default = [ ]; | ||
description = "Extra arguments"; | ||
}; | ||
keyFile = lib.mkOption { | ||
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname; | ||
default = null; | ||
description = "Path to the key for encryption"; | ||
example = "/tmp/disk.key"; | ||
}; | ||
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."; | ||
}; | ||
_parent = lib.mkOption { | ||
internal = true; | ||
default = parent; | ||
}; | ||
_meta = lib.mkOption { | ||
internal = true; | ||
readOnly = true; | ||
type = lib.types.functionTo diskoLib.jsonType; | ||
default = dev: { }; | ||
description = "Metadata"; | ||
}; | ||
_create = diskoLib.mkCreateOption { | ||
inherit config options; | ||
default = '' | ||
bcachefs format ${config.device} ${toString config.extraArgs} | ||
''; | ||
}; | ||
_mount = diskoLib.mkMountOption { | ||
inherit config options; | ||
default = { | ||
fs = lib.optionalAttrs (config.mountpoint != null) { | ||
${config.mountpoint} = '' | ||
if ! findmnt ${config.device} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then | ||
mount -t bcachefs ${config.device} "${rootMountPoint}${config.mountpoint}" \ | ||
${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \ | ||
-o X-mount.mkdir | ||
fi | ||
''; | ||
}; | ||
}; | ||
}; | ||
_config = lib.mkOption { | ||
internal = true; | ||
readOnly = true; | ||
default = [ | ||
(lib.optional (config.mountpoint != null) { | ||
fileSystems.${config.mountpoint} = { | ||
device = config.device; | ||
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 pkgs.coreutils ]; | ||
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