-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
1 changed file
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ config, options, lib, diskoLib, optionTypes, ... }: | ||
{ | ||
options = { | ||
type = lib.mkOption { | ||
type = lib.types.enum [ "bcachefs" ]; | ||
internal = true; | ||
description = "Type"; | ||
}; | ||
name = lib.mkOption { | ||
type = lib.types.str; | ||
description = "Name of the Bcachefs partition"; | ||
}; | ||
keyFile = lib.mkOption { | ||
type = lib.types.nullOr optionTypes.absolute-pathname; | ||
default = null; | ||
description = "Path to the key for encryption"; | ||
example = "/tmp/disk.key"; | ||
}; | ||
content = diskoLib.deviceType; | ||
_meta = lib.mkOption { | ||
internal = true; | ||
readOnly = true; | ||
type = lib.types.functionTo diskoLib.jsonType; | ||
default = dev: | ||
lib.optionalAttrs (config.content != null) (config.content._meta dev); | ||
description = "Metadata"; | ||
}; | ||
_create = diskoLib.mkCreateOption { | ||
inherit config options; | ||
default = { dev }: '' | ||
mkfs.bcachefs ${dev} | ||
if ${config.keyFile}; then | ||
bcachefs set-passphrase ${dev} < ${config.keyFile} | ||
bcachefs unlock ${dev} < ${config.keyFile} | ||
fi | ||
''; | ||
}; | ||
_mount = diskoLib.mkMountOption { | ||
inherit config options; | ||
default = { dev }: '' | ||
cryptsetup status ${config.name} >/dev/null 2>/dev/null || | ||
cryptsetup luksOpen ${dev} ${config.name} ${lib.optionalString (config.keyFile != null) "--key-file ${config.keyFile}"} | ||
${lib.optionalString (config.content != null) contentMount.dev or ""} | ||
''; | ||
}; | ||
_config = lib.mkOption { | ||
internal = true; | ||
readOnly = true; | ||
default = dev: [ ] | ||
# If initrdUnlock is true, then add a device entry to the initrd.luks.devices config. | ||
++ (lib.optional config.initrdUnlock [{ boot.initrd.luks.devices.${config.name}.device = dev; }]) | ||
++ (lib.optional (config.content != null) (config.content._config "/dev/mapper/${config.name}")); | ||
description = "NixOS configuration"; | ||
}; | ||
_pkgs = lib.mkOption { | ||
internal = true; | ||
readOnly = true; | ||
type = lib.types.functionTo (lib.types.listOf lib.types.package); | ||
default = pkgs: [ pkgs.cryptsetup ] ++ (lib.optionals (config.content != null) (config.content._pkgs pkgs)); | ||
description = "Packages"; | ||
}; | ||
}; | ||
} |