mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 13:03:28 +01:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b1335e935 |
No files matched your search
@@ -76,7 +76,6 @@ A simple disko configuration may look like this:
|
|||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
format = "vfat";
|
format = "vfat";
|
||||||
mountpoint = "/boot";
|
mountpoint = "/boot";
|
||||||
mountOptions = [ "umask=0077" ];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
root = {
|
root = {
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ let
|
|||||||
diskoScript =
|
diskoScript =
|
||||||
if hasDiskoConfigFlake then
|
if hasDiskoConfigFlake then
|
||||||
diskoEval
|
diskoEval
|
||||||
else if hasDiskoModuleFlake then
|
else if (lib.traceValSeq hasDiskoModuleFlake) then
|
||||||
(builtins.getFlake flake).nixosConfigurations.${flakeAttr}.config.system.build.${diskoAttr} or (
|
(builtins.getFlake flake).nixosConfigurations.${flakeAttr}.config.system.build.${diskoAttr} or (
|
||||||
pkgs.writeShellScriptBin "disko-compat-error" ''
|
pkgs.writeShellScriptBin "disko-compat-error" ''
|
||||||
echo 'Error: Attribute `nixosConfigurations.${flakeAttr}.config.system.build.${diskoAttr}` >&2
|
echo 'Error: Attribute `nixosConfigurations.${flakeAttr}.config.system.build.${diskoAttr}` >&2
|
||||||
|
|||||||
@@ -110,15 +110,6 @@ parseArgs() {
|
|||||||
extraSystemConfig="$2"
|
extraSystemConfig="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--disko-system-config)
|
|
||||||
if [[ $# -lt 2 ]]; then
|
|
||||||
echo "Option $1 requires one JSON argument." >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
extraDiskoSystemConfig="$2"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
--extra-files)
|
--extra-files)
|
||||||
if [[ $# -lt 3 ]]; then
|
if [[ $# -lt 3 ]]; then
|
||||||
echo "Option $1 requires two arguments: source, destination" >&2
|
echo "Option $1 requires two arguments: source, destination" >&2
|
||||||
|
|||||||
+1
-1
@@ -204,7 +204,7 @@ of the NixOS manual. The following configuration for `grub` works for both EFI
|
|||||||
and BIOS systems. Add this to your configuration.nix, commenting out the
|
and BIOS systems. Add this to your configuration.nix, commenting out the
|
||||||
existing lines that configure `systemd-boot`. The entries will look like this:
|
existing lines that configure `systemd-boot`. The entries will look like this:
|
||||||
|
|
||||||
**Note:** It's not necessary to set `boot.loader.grub.device` here, since Disko
|
**Note:** Its not necessary to set `boot.loader.grub.device` here, since Disko
|
||||||
will take care of that automatically.
|
will take care of that automatically.
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ for example like this:
|
|||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
format = "vfat";
|
format = "vfat";
|
||||||
mountpoint = "/boot";
|
mountpoint = "/boot";
|
||||||
mountOptions = [ "umask=0077" ];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -67,7 +67,6 @@
|
|||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
format = "vfat";
|
format = "vfat";
|
||||||
mountpoint = "/boot";
|
mountpoint = "/boot";
|
||||||
mountOptions = [ "umask=0077" ];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
raid1 = {
|
raid1 = {
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
format = "vfat";
|
format = "vfat";
|
||||||
mountpoint = "/boot";
|
mountpoint = "/boot";
|
||||||
mountOptions = [ "umask=0077" ];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
"name with spaces" = {
|
"name with spaces" = {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
format = "vfat";
|
format = "vfat";
|
||||||
mountpoint = "/boot";
|
mountpoint = "/boot";
|
||||||
mountOptions = [ "umask=0077" ];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
empty = {
|
empty = {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
format = "vfat";
|
format = "vfat";
|
||||||
mountpoint = "/boot";
|
mountpoint = "/boot";
|
||||||
mountOptions = [ "umask=0077" ];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
format = "vfat";
|
format = "vfat";
|
||||||
mountpoint = "/boot";
|
mountpoint = "/boot";
|
||||||
mountOptions = [ "umask=0077" ];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,7 +37,6 @@
|
|||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
format = "vfat";
|
format = "vfat";
|
||||||
mountpoint = "/boot";
|
mountpoint = "/boot";
|
||||||
mountOptions = [ "umask=0077" ];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
raid1 = {
|
raid1 = {
|
||||||
|
|||||||
@@ -59,7 +59,6 @@
|
|||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
format = "vfat";
|
format = "vfat";
|
||||||
mountpoint = "/boot";
|
mountpoint = "/boot";
|
||||||
mountOptions = [ "umask=0077" ];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
{
|
|
||||||
disko.devices = {
|
|
||||||
disk = {
|
|
||||||
main = {
|
|
||||||
device = "/dev/disk/by-id/some-disk-id";
|
|
||||||
type = "disk";
|
|
||||||
content = {
|
|
||||||
type = "gpt";
|
|
||||||
partitions = {
|
|
||||||
ESP = {
|
|
||||||
type = "EF00";
|
|
||||||
size = "500M";
|
|
||||||
content = {
|
|
||||||
type = "filesystem";
|
|
||||||
format = "vfat";
|
|
||||||
mountpoint = "/boot";
|
|
||||||
mountOptions = [ "umask=0077" ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
root = {
|
|
||||||
size = "100%";
|
|
||||||
content = {
|
|
||||||
type = "filesystem";
|
|
||||||
format = "xfs";
|
|
||||||
mountpoint = "/";
|
|
||||||
mountOptions = [ "defaults" "pquota" ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -244,14 +244,11 @@
|
|||||||
type = "topology";
|
type = "topology";
|
||||||
vdev = [
|
vdev = [
|
||||||
{
|
{
|
||||||
# This syntax expects a disk called 'data3' with a gpt partition called 'zfs'.
|
mode = "mirror";
|
||||||
members = [ "data1" ];
|
members = [ "data1" "data2" ];
|
||||||
# It's also possible to use the full path of the device or partition
|
|
||||||
# members = [ "/dev/disk/by-id/wwn-0x5000c500af8b2a14" ];
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
mode = "mirror";
|
members = [ "data3" ];
|
||||||
members = [ "data2" "data3" ];
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
spare = [ "spare" ];
|
spare = [ "spare" ];
|
||||||
|
|||||||
+1
-19
@@ -72,7 +72,7 @@
|
|||||||
options.mountpoint = "legacy";
|
options.mountpoint = "legacy";
|
||||||
mountpoint = "/zfs_legacy_fs";
|
mountpoint = "/zfs_legacy_fs";
|
||||||
};
|
};
|
||||||
zfs_volume = {
|
zfs_testvolume = {
|
||||||
type = "zfs_volume";
|
type = "zfs_volume";
|
||||||
size = "10M";
|
size = "10M";
|
||||||
content = {
|
content = {
|
||||||
@@ -81,24 +81,6 @@
|
|||||||
mountpoint = "/ext4onzfs";
|
mountpoint = "/ext4onzfs";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
zfs_volume_no_content = {
|
|
||||||
type = "zfs_volume";
|
|
||||||
size = "10M";
|
|
||||||
};
|
|
||||||
zfs_encryptedvolume = {
|
|
||||||
type = "zfs_volume";
|
|
||||||
size = "10M";
|
|
||||||
options = {
|
|
||||||
encryption = "aes-256-gcm";
|
|
||||||
keyformat = "passphrase";
|
|
||||||
keylocation = "file:///tmp/secret.key";
|
|
||||||
};
|
|
||||||
content = {
|
|
||||||
type = "filesystem";
|
|
||||||
format = "ext4";
|
|
||||||
mountpoint = "/ext4onzfsencrypted";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
encrypted = {
|
encrypted = {
|
||||||
type = "zfs_fs";
|
type = "zfs_fs";
|
||||||
options = {
|
options = {
|
||||||
|
|||||||
Generated
+3
-3
@@ -2,11 +2,11 @@
|
|||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1736241350,
|
"lastModified": 1733749988,
|
||||||
"narHash": "sha256-CHd7yhaDigUuJyDeX0SADbTM9FXfiWaeNyY34FL1wQU=",
|
"narHash": "sha256-+5qdtgXceqhK5ZR1YbP1fAUsweBIrhL38726oIEAtDs=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "8c9fd3e564728e90829ee7dbac6edc972971cd0f",
|
"rev": "bc27f0fde01ce4e1bfec1ab122d72b7380278e68",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
nixosModules.default = self.nixosModules.disko; # convention
|
nixosModules.default = self.nixosModules.disko; # convention
|
||||||
nixosModules.disko = ./module.nix;
|
nixosModules.disko.imports = [ ./module.nix ];
|
||||||
lib = diskoLib;
|
lib = diskoLib;
|
||||||
packages = forAllSystems (system:
|
packages = forAllSystems (system:
|
||||||
let
|
let
|
||||||
|
|||||||
+1
-5
@@ -2,7 +2,6 @@
|
|||||||
, flakeAttr
|
, flakeAttr
|
||||||
, diskMappings
|
, diskMappings
|
||||||
, extraSystemConfig ? "{}"
|
, extraSystemConfig ? "{}"
|
||||||
, extraDiskoSystemConfig ? "{}"
|
|
||||||
, writeEfiBootEntries ? false
|
, writeEfiBootEntries ? false
|
||||||
, rootMountPoint ? "/mnt"
|
, rootMountPoint ? "/mnt"
|
||||||
,
|
,
|
||||||
@@ -42,9 +41,6 @@ let
|
|||||||
{
|
{
|
||||||
disko.rootMountPoint = rootMountPoint;
|
disko.rootMountPoint = rootMountPoint;
|
||||||
disko.devices.disk = lib.mkVMOverride cleanedDisks;
|
disko.devices.disk = lib.mkVMOverride cleanedDisks;
|
||||||
imports = [
|
|
||||||
({ _file = "disko-install --system-config"; } // (builtins.fromJSON extraDiskoSystemConfig))
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
@@ -55,7 +51,7 @@ let
|
|||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
{
|
{
|
||||||
boot.loader.efi.canTouchEfiVariables = lib.mkVMOverride writeEfiBootEntries;
|
boot.loader.efi.canTouchEfiVariables = lib.mkVMOverride writeEfiBootEntries;
|
||||||
boot.loader.grub.devices = lib.mkVMOverride (lib.attrValues diskMappings);
|
boot.loader.grub.devices = lib.mkVMOverride diskoSystem.config.boot.loader.grub.devices;
|
||||||
imports = [
|
imports = [
|
||||||
({ _file = "disko-install --system-config"; } // (builtins.fromJSON extraSystemConfig))
|
({ _file = "disko-install --system-config"; } // (builtins.fromJSON extraSystemConfig))
|
||||||
];
|
];
|
||||||
|
|||||||
+4
-12
@@ -13,16 +13,8 @@ let
|
|||||||
|
|
||||||
configSupportsZfs = config.boot.supportedFilesystems.zfs or false;
|
configSupportsZfs = config.boot.supportedFilesystems.zfs or false;
|
||||||
vmTools = pkgs.vmTools.override
|
vmTools = pkgs.vmTools.override
|
||||||
({
|
{
|
||||||
rootModules = [
|
rootModules = [ "9p" "9pnet_virtio" "virtio_pci" "virtio_blk" ]
|
||||||
"9p" "9pnet_virtio" # we can drop those in future if we stop supporting 24.11
|
|
||||||
|
|
||||||
"virtiofs"
|
|
||||||
"virtio_pci"
|
|
||||||
"virtio_blk"
|
|
||||||
"virtio_balloon"
|
|
||||||
"virtio_rng"
|
|
||||||
]
|
|
||||||
++ (lib.optional configSupportsZfs "zfs")
|
++ (lib.optional configSupportsZfs "zfs")
|
||||||
++ cfg.extraRootModules;
|
++ cfg.extraRootModules;
|
||||||
kernel = pkgs.aggregateModules
|
kernel = pkgs.aggregateModules
|
||||||
@@ -32,7 +24,7 @@ let
|
|||||||
// lib.optionalAttrs (diskoLib.vmToolsSupportsCustomQemu lib)
|
// lib.optionalAttrs (diskoLib.vmToolsSupportsCustomQemu lib)
|
||||||
{
|
{
|
||||||
customQemu = cfg.qemu;
|
customQemu = cfg.qemu;
|
||||||
});
|
};
|
||||||
cleanedConfig = diskoLib.testLib.prepareDiskoConfig config diskoLib.testLib.devices;
|
cleanedConfig = diskoLib.testLib.prepareDiskoConfig config diskoLib.testLib.devices;
|
||||||
systemToInstall = extendModules {
|
systemToInstall = extendModules {
|
||||||
modules = [
|
modules = [
|
||||||
@@ -121,7 +113,7 @@ in
|
|||||||
{
|
{
|
||||||
buildInputs = dependencies;
|
buildInputs = dependencies;
|
||||||
inherit preVM QEMU_OPTS;
|
inherit preVM QEMU_OPTS;
|
||||||
postVM = cfg.extraPostVM;
|
postVm = cfg.extraPostVM;
|
||||||
inherit (diskoCfg) memSize;
|
inherit (diskoCfg) memSize;
|
||||||
}
|
}
|
||||||
(partitioner + installer));
|
(partitioner + installer));
|
||||||
|
|||||||
@@ -0,0 +1,155 @@
|
|||||||
|
{ config, options, lib, diskoLib, parent, ... }:
|
||||||
|
# EXPERIMENTAL: This module provides verification of install images through dm-verity
|
||||||
|
# We do not provide updating nixos configuration through nixos-rebuild switch, when using this.
|
||||||
|
# This is mainly useful in the context of generated images, that are booted with secure boot.
|
||||||
|
let
|
||||||
|
diskoConfig = config;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
type = lib.mkOption {
|
||||||
|
type = lib.types.enum [ "verity" ];
|
||||||
|
internal = true;
|
||||||
|
description = "Type";
|
||||||
|
};
|
||||||
|
name = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = config._module.args.name;
|
||||||
|
description = "Name of the veritysetup device";
|
||||||
|
};
|
||||||
|
# can we get those from device directly?
|
||||||
|
dataDevice = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
description = "Device to store the data";
|
||||||
|
};
|
||||||
|
hashDevice = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
description = "Device to store the merkle tree";
|
||||||
|
};
|
||||||
|
extraFormatArgs = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [ ];
|
||||||
|
description = "Extra arguments to pass to `veritysetup format`";
|
||||||
|
example = [ "--debug" ];
|
||||||
|
};
|
||||||
|
extraOpenArgs = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [ ];
|
||||||
|
description = "Extra arguments to pass to `cryptsetup luksOpen` when opening";
|
||||||
|
example = [ "--timeout 10" ];
|
||||||
|
};
|
||||||
|
content = diskoLib.deviceType { parent = config; device = "/dev/mapper/${config.name}"; };
|
||||||
|
_parent = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
default = parent;
|
||||||
|
};
|
||||||
|
_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 = {};
|
||||||
|
};
|
||||||
|
_mount = diskoLib.mkMountOption {
|
||||||
|
inherit config options;
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
|
_unmount = diskoLib.mkMountOption {
|
||||||
|
inherit config options;
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
|
_config = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
readOnly = true;
|
||||||
|
default = [
|
||||||
|
({config, pkgs, ...}: {
|
||||||
|
# Maybe secureboot should be left to the user?
|
||||||
|
boot.uki.settings = {
|
||||||
|
# TODO
|
||||||
|
# SecureBootPrivateKey = "./out";
|
||||||
|
};
|
||||||
|
# TODO: upstream this.
|
||||||
|
assertions = [
|
||||||
|
{
|
||||||
|
assertion = config.boot.inird.systemd.enable;
|
||||||
|
message = ''
|
||||||
|
veritysetup with disko requires systemd in the initrd to be enabled.
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
];
|
||||||
|
# TODO: we want actually
|
||||||
|
boot.kernelParams = [
|
||||||
|
"systemd.verity_root_data=${diskoConfig.dataDevice}"
|
||||||
|
"systemd.verity_root_hash=${diskoConfig.hashDevice}"
|
||||||
|
];
|
||||||
|
boot.initrd = {
|
||||||
|
availableKernelModules = [ "dm_mod" "dm_verity" ];
|
||||||
|
# We need LVM for dm-verity to work.
|
||||||
|
services.lvm.enable = true;
|
||||||
|
|
||||||
|
systemd = {
|
||||||
|
additionalUpstreamUnits = [ "veritysetup-pre.target" "veritysetup.target" "remote-veritysetup.target" ];
|
||||||
|
storePaths = [
|
||||||
|
"${config.boot.initrd.systemd.package}/lib/systemd/systemd-veritysetup"
|
||||||
|
"${config.boot.initrd.systemd.package}/lib/systemd/system-generators/systemd-veritysetup-generator"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
boot.bootspec.enable = true;
|
||||||
|
boot.loader.external = {
|
||||||
|
enable = true;
|
||||||
|
installHook =
|
||||||
|
let
|
||||||
|
bootspecNamespace = ''"org.nixos.bootspec.v1"'';
|
||||||
|
installer = pkgs.writeShellApplication {
|
||||||
|
name = "install-uki";
|
||||||
|
runtimeInputs = with pkgs; [ jq systemd binutils ];
|
||||||
|
text = ''
|
||||||
|
boot_json=/nix/var/nix/profiles/system-1-link/boot.json
|
||||||
|
tempdir=$(mktemp -d)
|
||||||
|
trap 'rm -rf "$tempdir"' EXIT
|
||||||
|
kernel=$(jq -r '.${bootspecNamespace}.kernel' "$boot_json")
|
||||||
|
initrd=$(jq -r '.${bootspecNamespace}.initrd' "$boot_json")
|
||||||
|
init=$(jq -r '.${bootspecNamespace}.init' "$boot_json")
|
||||||
|
|
||||||
|
# TODO: get access to the unmount script for config.dataDevice by injecting toplevel-config into disko
|
||||||
|
veritysetup format ${config.dataDevice} ${config.hashDevice} \
|
||||||
|
--root-hash-file "$tempdir/verity_roothash_${config.name}"
|
||||||
|
|
||||||
|
${pkgs.systemdUkify}/lib/systemd/ukify \
|
||||||
|
"$kernel" \
|
||||||
|
"$initrd" \
|
||||||
|
--stub="${pkgs.systemd}/lib/systemd/boot/efi/linux${pkgs.hostPlatform.efiArch}.efi.stub" \
|
||||||
|
--cmdline="init=$init ${builtins.toString config.boot.kernelParams} roothash=$(<$tempdir/verity_roothash_${config.name})" \
|
||||||
|
--os-release="@${config.system.build.etc}/etc/os-release" \
|
||||||
|
--output=uki.efi
|
||||||
|
|
||||||
|
esp=${config.boot.loader.efi.efiSysMountPoint}
|
||||||
|
|
||||||
|
bootctl install --esp-path="$esp"
|
||||||
|
install uki.efi "$esp"/EFI/Linux/
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
in
|
||||||
|
"${lib.getExe installer}";
|
||||||
|
};
|
||||||
|
|
||||||
|
})
|
||||||
|
] ++ (lib.optional (config.content != null) config.content._config);
|
||||||
|
description = "NixOS configuration";
|
||||||
|
};
|
||||||
|
_pkgs = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
readOnly = true;
|
||||||
|
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||||
|
default = pkgs: lib.optionals (config.content != null) (config.content._pkgs pkgs);
|
||||||
|
description = "Packages";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
+2
-10
@@ -101,13 +101,7 @@
|
|||||||
_mount = diskoLib.mkMountOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default =
|
default =
|
||||||
(lib.optionalAttrs (config.options.keylocation or "none" != "none") {
|
lib.optionalAttrs (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") {
|
||||||
dev = ''
|
|
||||||
if [ "$(zfs get keystatus ${config._name} -H -o value)" == "unavailable" ]; then
|
|
||||||
zfs load-key ${config._name}
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
}) // lib.optionalAttrs (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") {
|
|
||||||
fs.${config.mountpoint} = ''
|
fs.${config.mountpoint} = ''
|
||||||
if ! findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
|
if ! findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
|
||||||
mount ${config._name} "${rootMountPoint}${config.mountpoint}" \
|
mount ${config._name} "${rootMountPoint}${config.mountpoint}" \
|
||||||
@@ -123,9 +117,7 @@
|
|||||||
_unmount = diskoLib.mkUnmountOption {
|
_unmount = diskoLib.mkUnmountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default =
|
default =
|
||||||
(lib.optionalAttrs (config.options.keylocation or "none" != "none") {
|
lib.optionalAttrs (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") {
|
||||||
dev = "zfs unload-key ${config.name}";
|
|
||||||
}) // lib.optionalAttrs (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") {
|
|
||||||
fs.${config.mountpoint} = ''
|
fs.${config.mountpoint} = ''
|
||||||
if findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
|
if findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
|
||||||
umount "${rootMountPoint}${config.mountpoint}"
|
umount "${rootMountPoint}${config.mountpoint}"
|
||||||
|
|||||||
@@ -66,30 +66,13 @@
|
|||||||
};
|
};
|
||||||
_mount = diskoLib.mkMountOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = {
|
default =
|
||||||
dev = ''
|
lib.optionalAttrs (config.content != null) config.content._mount;
|
||||||
${lib.optionalString (config.options.keylocation or "none" != "none") ''
|
|
||||||
if [ "$(zfs get keystatus ${config.name} -H -o value)" == "unavailable" ]; then
|
|
||||||
zfs load-key ${config.name}
|
|
||||||
fi
|
|
||||||
''}
|
|
||||||
|
|
||||||
${config.content._mount.dev or ""}
|
|
||||||
'';
|
|
||||||
fs = config.content._mount.fs or { };
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
_unmount = diskoLib.mkUnmountOption {
|
_unmount = diskoLib.mkUnmountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = {
|
default =
|
||||||
dev = ''
|
lib.optionalAttrs (config.content != null) config.content._unmount;
|
||||||
${lib.optionalString (config.options.keylocation or "none" != "none") "zfs unload-key ${config.name}"}
|
|
||||||
|
|
||||||
${config.content._unmount.dev or ""}
|
|
||||||
'';
|
|
||||||
|
|
||||||
fs = config.content._unmount.fs or {};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
_config = lib.mkOption {
|
_config = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|||||||
+16
-51
@@ -25,44 +25,6 @@ in
|
|||||||
};
|
};
|
||||||
mode = lib.mkOption {
|
mode = lib.mkOption {
|
||||||
default = "";
|
default = "";
|
||||||
example = {
|
|
||||||
mode = {
|
|
||||||
topology = {
|
|
||||||
type = "topology";
|
|
||||||
vdev = [
|
|
||||||
{
|
|
||||||
# Members can be either specified by a full path or by a disk name
|
|
||||||
# This is example uses the full path
|
|
||||||
members = [ "/dev/disk/by-id/wwn-0x5000c500af8b2a14" ];
|
|
||||||
}
|
|
||||||
];
|
|
||||||
log = [
|
|
||||||
{
|
|
||||||
# Example using gpt partition labels
|
|
||||||
# This expects an disk called `ssd` with a gpt partition called `zfs`
|
|
||||||
# disko.devices.disk.ssd = {
|
|
||||||
# type = "disk";
|
|
||||||
# device = "/dev/nvme0n1";
|
|
||||||
# content = {
|
|
||||||
# type = "gpt";
|
|
||||||
# partitions = {
|
|
||||||
# zfs = {
|
|
||||||
# size = "100%";
|
|
||||||
# content = {
|
|
||||||
# type = "zfs";
|
|
||||||
# # use your own pool name here
|
|
||||||
# pool = "zroot";
|
|
||||||
# };
|
|
||||||
# };
|
|
||||||
# };
|
|
||||||
# };
|
|
||||||
# };
|
|
||||||
members = [ "ssd" ];
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
type = (lib.types.oneOf [
|
type = (lib.types.oneOf [
|
||||||
(lib.types.enum modeOptions)
|
(lib.types.enum modeOptions)
|
||||||
(lib.types.attrsOf (diskoLib.subType {
|
(lib.types.attrsOf (diskoLib.subType {
|
||||||
@@ -337,30 +299,33 @@ in
|
|||||||
inherit config options;
|
inherit config options;
|
||||||
default =
|
default =
|
||||||
let
|
let
|
||||||
datasetFilesystemsMounts = diskoLib.deepMergeMap (dataset: dataset._mount.fs or {}) (lib.attrValues config.datasets);
|
datasetMounts = diskoLib.deepMergeMap (dataset: dataset._mount) (lib.attrValues config.datasets);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
dev = ''
|
dev = ''
|
||||||
zpool list "${config.name}" >/dev/null 2>/dev/null ||
|
zpool list "${config.name}" >/dev/null 2>/dev/null ||
|
||||||
zpool import -l -R ${rootMountPoint} "${config.name}"
|
zpool import -l -R ${rootMountPoint} "${config.name}"
|
||||||
|
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues datasetMounts)}
|
||||||
${lib.concatMapStrings (x: x._mount.dev or "") (lib.attrValues config.datasets)}
|
|
||||||
'';
|
'';
|
||||||
fs = datasetFilesystemsMounts;
|
fs = datasetMounts.fs or { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
_unmount = diskoLib.mkUnmountOption {
|
_unmount = diskoLib.mkUnmountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = {
|
default =
|
||||||
dev = ''
|
let
|
||||||
${lib.concatMapStrings (dataset: dataset._unmount.dev or "") (lib.attrValues config.datasets)}
|
datasetUnmounts = diskoLib.deepMergeMap (dataset: dataset._unmount) (lib.attrValues config.datasets);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
dev = ''
|
||||||
|
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues datasetUnmounts)}
|
||||||
|
|
||||||
if zpool list "${config.name}" >/dev/null 2>/dev/null; then
|
if zpool list "${config.name}" >/dev/null 2>/dev/null; then
|
||||||
zpool export "${config.name}"
|
zpool export "${config.name}"
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
fs = diskoLib.deepMergeMap (dataset: dataset._unmount.fs or {}) (lib.attrValues config.datasets);
|
fs = datasetUnmounts.fs or { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
_config = lib.mkOption {
|
_config = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
|
|||||||
+2
-2
@@ -59,9 +59,9 @@ in
|
|||||||
extraPostVM = lib.mkOption {
|
extraPostVM = lib.mkOption {
|
||||||
type = lib.types.lines;
|
type = lib.types.lines;
|
||||||
description = ''
|
description = ''
|
||||||
extra shell code to execute once the disk image(s) have been successfully created and moved to $out
|
extra shell code to execute once the disk image(s) have been succesfully created and moved to $out
|
||||||
'';
|
'';
|
||||||
default = ":";
|
default = "";
|
||||||
example = lib.literalExpression ''
|
example = lib.literalExpression ''
|
||||||
''${pkgs.zstd}/bin/zstd --compress $out/*raw
|
''${pkgs.zstd}/bin/zstd --compress $out/*raw
|
||||||
rm $out/*raw
|
rm $out/*raw
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
{ pkgs ? import <nixpkgs> { }
|
|
||||||
, diskoLib ? pkgs.callPackage ../lib { }
|
|
||||||
}:
|
|
||||||
diskoLib.testLib.makeDiskoTest {
|
|
||||||
inherit pkgs;
|
|
||||||
name = "xfs";
|
|
||||||
disko-config = ../example/xfs-with-quota.nix;
|
|
||||||
extraTestScript = ''
|
|
||||||
machine.succeed("mountpoint /");
|
|
||||||
|
|
||||||
machine.succeed("xfs_quota -c 'print' / | grep -q '(pquota)'")
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
@@ -57,9 +57,9 @@ diskoLib.testLib.makeDiskoTest {
|
|||||||
vdev = ""
|
vdev = ""
|
||||||
actual.sort()
|
actual.sort()
|
||||||
expected=sorted([
|
expected=sorted([
|
||||||
'zroot /dev/disk/by-partlabel/disk-data1-zfs',
|
'zroot /dev/disk/by-partlabel/disk-data3-zfs',
|
||||||
|
'zroot mirror /dev/disk/by-partlabel/disk-data1-zfs',
|
||||||
'zroot mirror /dev/disk/by-partlabel/disk-data2-zfs',
|
'zroot mirror /dev/disk/by-partlabel/disk-data2-zfs',
|
||||||
'zroot mirror /dev/disk/by-partlabel/disk-data3-zfs',
|
|
||||||
'dedup /dev/disk/by-partlabel/disk-dedup3-zfs',
|
'dedup /dev/disk/by-partlabel/disk-dedup3-zfs',
|
||||||
'dedup mirror /dev/disk/by-partlabel/disk-dedup1-zfs',
|
'dedup mirror /dev/disk/by-partlabel/disk-dedup1-zfs',
|
||||||
'dedup mirror /dev/disk/by-partlabel/disk-dedup2-zfs',
|
'dedup mirror /dev/disk/by-partlabel/disk-dedup2-zfs',
|
||||||
|
|||||||
+2
-5
@@ -11,8 +11,7 @@ diskoLib.testLib.makeDiskoTest {
|
|||||||
fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this!
|
fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this!
|
||||||
};
|
};
|
||||||
extraTestScript = ''
|
extraTestScript = ''
|
||||||
machine.succeed("test -b /dev/zvol/zroot/zfs_volume");
|
machine.succeed("test -b /dev/zvol/zroot/zfs_testvolume");
|
||||||
machine.succeed("test -b /dev/zvol/zroot/zfs_encryptedvolume");
|
|
||||||
|
|
||||||
def assert_property(ds, property, expected_value):
|
def assert_property(ds, property, expected_value):
|
||||||
out = machine.succeed(f"zfs get -H {property} {ds} -o value").rstrip()
|
out = machine.succeed(f"zfs get -H {property} {ds} -o value").rstrip()
|
||||||
@@ -24,8 +23,7 @@ diskoLib.testLib.makeDiskoTest {
|
|||||||
assert_property("zroot/zfs_fs", "compression", "zstd")
|
assert_property("zroot/zfs_fs", "compression", "zstd")
|
||||||
assert_property("zroot", "com.sun:auto-snapshot", "false")
|
assert_property("zroot", "com.sun:auto-snapshot", "false")
|
||||||
assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true")
|
assert_property("zroot/zfs_fs", "com.sun:auto-snapshot", "true")
|
||||||
assert_property("zroot/zfs_volume", "volsize", "10M")
|
assert_property("zroot/zfs_testvolume", "volsize", "10M")
|
||||||
assert_property("zroot/zfs_encryptedvolume", "volsize", "10M")
|
|
||||||
assert_property("zroot/zfs_unmounted_fs", "mountpoint", "none")
|
assert_property("zroot/zfs_unmounted_fs", "mountpoint", "none")
|
||||||
|
|
||||||
machine.succeed("zfs get name zroot@blank")
|
machine.succeed("zfs get name zroot@blank")
|
||||||
@@ -33,7 +31,6 @@ diskoLib.testLib.makeDiskoTest {
|
|||||||
machine.succeed("mountpoint /zfs_fs");
|
machine.succeed("mountpoint /zfs_fs");
|
||||||
machine.succeed("mountpoint /zfs_legacy_fs");
|
machine.succeed("mountpoint /zfs_legacy_fs");
|
||||||
machine.succeed("mountpoint /ext4onzfs");
|
machine.succeed("mountpoint /ext4onzfs");
|
||||||
machine.succeed("mountpoint /ext4onzfsencrypted");
|
|
||||||
machine.succeed("mountpoint /zfs_crypted");
|
machine.succeed("mountpoint /zfs_crypted");
|
||||||
machine.succeed("zfs get keystatus zroot/encrypted");
|
machine.succeed("zfs get keystatus zroot/encrypted");
|
||||||
machine.succeed("zfs get keystatus zroot/encrypted/test");
|
machine.succeed("zfs get keystatus zroot/encrypted/test");
|
||||||
|
|||||||
Reference in new issue
Block a user