forked from nix-community/disko
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
160 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,70 @@ | ||
{ config, options, lib, diskoLib, parent, device, ... }: | ||
{ | ||
options = { | ||
type = lib.mkOption { | ||
type = lib.types.enum [ "bcachefs" ]; | ||
internal = true; | ||
description = "Type"; | ||
}; | ||
device = lib.mkOption { | ||
type = lib.types.str; | ||
description = "Device"; | ||
default = device; | ||
}; | ||
|
||
name = lib.mkOption { | ||
type = lib.types.str; | ||
description = "Name"; | ||
}; | ||
|
||
label = lib.mkOption { | ||
type = lib.types.str; | ||
description = "Label"; | ||
}; | ||
|
||
formatOptions = lib.mkOption { | ||
type = lib.types.listOf lib.types.str; | ||
default = [ "defaults" ]; | ||
description = "Format options"; | ||
}; | ||
|
||
_parent = lib.mkOption { | ||
internal = true; | ||
default = parent; | ||
}; | ||
_meta = lib.mkOption { | ||
internal = true; | ||
readOnly = true; | ||
type = lib.types.functionTo diskoLib.jsonType; | ||
default = dev: { | ||
deviceDependencies.bcachefspool.${config.name} = [ dev ]; | ||
}; | ||
description = "Metadata"; | ||
}; | ||
_create = diskoLib.mkCreateOption { | ||
inherit config options; | ||
default = '' | ||
echo ${config.device} >>"$disko_devices_dir"/bcachefs_${config.name}/devices | ||
echo ${config.label} >>"$disko_devices_dir"/bcachefs_${config.name}/labels | ||
echo ${lib.concatStringsSep " " config.formatOptions} >>"$disko_devices_dir"/bcachefs_${config.name}/format_options | ||
''; | ||
}; | ||
_mount = diskoLib.mkMountOption { | ||
inherit config options; | ||
default = { }; | ||
}; | ||
_config = lib.mkOption { | ||
internal = true; | ||
readOnly = true; | ||
default = [ ]; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
{ config, options, lib, diskoLib, ... }: | ||
{ | ||
options = { | ||
name = lib.mkOption { | ||
type = lib.types.str; | ||
default = config._module.args.name; | ||
description = "Name"; | ||
}; | ||
|
||
type = lib.mkOption { | ||
type = lib.types.enum [ "bcachefspool" ]; | ||
default = "bcachefspool"; | ||
internal = true; | ||
description = "Type"; | ||
}; | ||
|
||
formatOptions = lib.mkOption { | ||
type = lib.types.listOf lib.types.str; | ||
default = [ "defaults" ]; | ||
description = "Format options"; | ||
}; | ||
|
||
mountOptions = lib.mkOption { | ||
type = lib.types.listOf lib.types.str; | ||
default = [ "defaults" ]; | ||
description = "Mount options"; | ||
}; | ||
|
||
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 = diskoLib.jsonType; | ||
default = | ||
lib.optionalAttrs (config.content != null) (config.content._meta [ "bcachefspool" config.name ]); | ||
description = "Metadata"; | ||
}; | ||
|
||
_create = diskoLib.mkCreateOption { | ||
inherit config options; | ||
default = '' | ||
readarray -t bcachefs_devices < <(cat "$disko_devices_dir"/bcachefs_${config.name}/devices) | ||
readarray -t bcachefs_labels < <(cat "$disko_devices_dir"/bcachefs_${config.name}/labels) | ||
readarray -t bcachefs_format_options < <(cat "$disko_devices_dir"/bcachefs_${config.name}/format_options) | ||
device_configs=() | ||
for ((i=0; i<''${#bcachefs_devices[@]}; i++)); do | ||
device=''${bcachefs_devices[$i]} | ||
label=''${bcachefs_labels[$i]} | ||
format_options=''${bcachefs_format_options[$i]} | ||
device_configs+=("--label=$label $format_options $device") | ||
done | ||
bcachefs format --fs_label=${config.name} ${lib.concatStringsSep " " config.formatOptions} \ | ||
$(IFS=' \' ; echo "''${device_configs[*]}") | ||
''; | ||
}; | ||
|
||
_mount = diskoLib.mkMountOption { | ||
inherit config options; | ||
default = "TODO"; | ||
}; | ||
|
||
_config = lib.mkOption { | ||
internal = true; | ||
readOnly = true; | ||
default = lib.optional (config.options.mountpoint or "" != "none") { | ||
fileSystems.${config.mountpoint} = { | ||
device = "${lib.concatStringsSep ":" config.formatOptions}"; | ||
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: []; | ||
description = "Packages"; | ||
}; | ||
}; | ||
} |