summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLassulus <github@lassul.us>2022-11-09 13:26:43 +0100
committerGitHub <noreply@github.com>2022-11-09 13:26:43 +0100
commit45ef21831ee493de5efa97f48f1c31ca9dd54764 (patch)
treed4efbdf4713aa4428a4922c0389ca4c61c808b9e
parentc96ccd7d9fb48b8283e84811c2355a3c39bb2a52 (diff)
parent0af2a7c206bd69ecdc01361e12c7cb0ec9820911 (diff)
Merge pull request #48 from nix-community/module
-rw-r--r--README.md236
-rw-r--r--cli.nix19
-rw-r--r--default.nix21
-rwxr-xr-xdisko94
-rw-r--r--example/boot-raid1.nix2
-rw-r--r--example/btrfs-subvolumes.nix2
-rw-r--r--example/complex.nix2
-rw-r--r--example/gpt-bios-compat.nix2
-rw-r--r--example/luks-lvm.nix2
-rw-r--r--example/lvm-raid.nix2
-rw-r--r--example/mdadm.nix2
-rw-r--r--example/simple-efi.nix40
-rw-r--r--example/with-lib.nix35
-rw-r--r--example/zfs-over-legacy.nix2
-rw-r--r--example/zfs.nix2
-rw-r--r--flake.lock27
-rw-r--r--flake.nix39
-rw-r--r--module.nix43
-rw-r--r--tests/boot-raid1.nix2
-rw-r--r--tests/btrfs-subvolumes.nix2
-rw-r--r--tests/cli.nix28
-rw-r--r--tests/complex.nix2
-rw-r--r--tests/gpt-bios-compat.nix2
-rw-r--r--tests/lib.nix56
-rw-r--r--tests/luks-lvm.nix2
-rw-r--r--tests/lvm-raid.nix2
-rw-r--r--tests/mdadm.nix2
-rw-r--r--tests/module.nix28
-rw-r--r--tests/simple-efi.nix9
-rw-r--r--tests/with-lib.nix11
-rw-r--r--tests/zfs-over-legacy.nix2
-rw-r--r--tests/zfs.nix2
-rw-r--r--types.nix253
33 files changed, 764 insertions, 211 deletions
diff --git a/README.md b/README.md
index eb06ac8..20dea6f 100644
--- a/README.md
+++ b/README.md
@@ -1,80 +1,182 @@
-disko
-=====
+# disko - declarative disk partitioning
-nix-powered automatic disk partitioning
+Disko takes the NixOS module system and makes it work for disk partitioning
+as well.
-Usage
-=====
+I wanted to write a curses NixOS installer, and that was the first step that I
+hit; the disk formatting is a manual process. Once that's done, the NixOS
+system itself is declarative, but the actual formatting of disks is manual.
-Master Boot Record
-------------------
-This is how your iso configuation may look like
+## Features
+
+* supports LVM, ZFS, btrfs, GPT, mdadm, ext4, ...
+* supports recursive layouts
+* outputs a NixOS-compatible module
+* CLI
+
+## How-to guides
+
+### NixOS installation
+
+During the NixOS installation process, replace the [Partitioning and
+formatting](https://nixos.org/manual/nixos/stable/index.html#sec-installation-partitioning)
+steps with the following:
+
+1. Find a disk layout in ./examples that you like.
+2. Write the config based on the example and your disk layout.
+4. Run the CLI (`nix run github:nix-community/disko`) to apply the changes.
+5. FIXME: Copy the disko module and disk layout around.
+6. Continue the NixOS installation.
+
+### Using without NixOS
+
+## Reference
+
+### Module options
+
+TODO: link to generated module options
+
+### Examples
+
+./examples
+
+### CLI
+
+TODO: output of the cli --help
+
+## Installing NixOS module
+
+You can use the NixOS module in one of the following ways:
+
+### Flakes
+
+If you use nix flakes support:
+
+``` nix
+{
+ inputs.disko.url = "github:nix-community/disko";
+ inputs.disko.inputs.nixpkgs.follows = "nixpkgs";
+
+ outputs = { self, nixpkgs, disko }: {
+ # change `yourhostname` to your actual hostname
+ nixosConfigurations.yourhostname = nixpkgs.lib.nixosSystem {
+ # change to your system:
+ system = "x86_64-linux";
+ modules = [
+ ./configuration.nix
+ disko.nixosModules.disko
+ ];
+ };
+ };
+}
+```
+
+### [niv](https://github.com/nmattia/niv) (Current recommendation)
+ First add it to niv:
+
+```console
+$ niv add nix-community/disko
+```
+
+ Then add the following to your configuration.nix in the `imports` list:
-/etc/nixos/configuration.nix
```nix
-{ pkgs, modulesPath, ... }:
-let
- disko = pkgs.callPackage (builtins.fetchGit {
- url = "https://github.com/nix-community/disko";
- ref = "master";
- }) {};
- cfg = {
- disk = {
- sda = {
- device = "/dev/sda";
- type = "device";
- content = {
- type = "table";
- format = "msdos";
- partitions = [
- {
- name = "root";
- type = "partition";
- part-type = "primary";
- start = "1M";
- end = "100%";
- bootable = true;
- content = {
- type = "filesystem";
- format = "ext4";
- mountpoint = "/";
- };
- }
- ];
- };
+{
+ imports = [ "${(import ./nix/sources.nix).disko}/modules/disko.nix" ];
+}
+```
+
+### nix-channel
+
+ As root run:
+
+```console
+$ nix-channel --add https://github.com/nix-community/disko/archive/main.tar.gz disko
+$ nix-channel --update
+```
+
+ Then add the following to your configuration.nix in the `imports` list:
+
+```nix
+{
+ imports = [ <disko/modules/disko.nix> ];
+}
+```
+
+### fetchTarball
+
+ Add the following to your configuration.nix:
+
+``` nix
+{
+ imports = [ "${builtins.fetchTarball "https://github.com/nix-community/disko/archive/main.tar.gz"}/modules/disko.nix" ];
+}
+```
+
+ or with pinning:
+
+```nix
+{
+ imports = let
+ # replace this with an actual commit id or tag
+ commit = "f2783a8ef91624b375a3cf665c3af4ac60b7c278";
+ in [
+ "${builtins.fetchTarball {
+ url = "https://github.com/nix-community/disko/archive/${commit}.tar.gz";
+ # replace this with an actual hash
+ sha256 = "0000000000000000000000000000000000000000000000000000";
+ }}/module.nix"
+ ];
+}
+```
+
+## Using the NixOS module
+
+```nix
+{
+ # checkout the example folder for how to configure different diska layouts
+ disko.devices = {
+ disk.sda = {
+ device = "/dev/sda";
+ type = "disk";
+ content = {
+ type = "table";
+ format = "gpt";
+ partitions = [
+ {
+ type = "partition";
+ name = "ESP";
+ start = "1MiB";
+ end = "100MiB";
+ bootable = true;
+ content = {
+ type = "filesystem";
+ format = "vfat";
+ mountpoint = "/boot";
+ };
+ }
+ {
+ name = "root";
+ type = "partition";
+ start = "100MiB";
+ end = "100%";
+ part-type = "primary";
+ bootable = true;
+ content = {
+ type = "filesystem";
+ format = "ext4";
+ mountpoint = "/";
+ };
+ }
+ ];
};
};
};
-in {
- imports = [
- (modulesPath + "/installer/cd-dvd/installation-cd-minimal.nix")
- ];
- environment.systemPackages = with pkgs;[
- (pkgs.writeScriptBin "tsp-create" (disko.create cfg))
- (pkgs.writeScriptBin "tsp-mount" (disko.mount cfg))
- ];
- ## Optional: Automatically creates a service which runs at startup to perform the partitioning
- #systemd.services.install-to-hd = {
- # enable = true;
- # wantedBy = ["multi-user.target"];
- # after = ["getty@tty1.service" ];
- # serviceConfig = {
- # Type = "oneshot";
- # ExecStart = [ (disko.create cfg) (disk.mount cfg) ];
- # StandardInput = "null";
- # StandardOutput = "journal+console";
- # StandardError = "inherit";
- # };
- #};
}
```
-After `nixos-rebuild switch` this will add a `tsp-create` and a `tsp-mount`
-command:
+this will configure `fileSystems` and other required NixOS options to boot the specified configuration.
-- **tsp-create**: creates & formats the partitions according to `tsp-disk.json`
-- **tsp-mount**: mounts the partitions to `/mnt`
+If you are on an installer, you probably want to disable `enableConfig`.
-GUID Partition Table, LVM and dm-crypt
---------------------------------------
-See `examples/`
+disko will create the scripts `disko-create` and `disko-mount` which can be used to create/mount the configured disk layout.
diff --git a/cli.nix b/cli.nix
new file mode 100644
index 0000000..ed80160
--- /dev/null
+++ b/cli.nix
@@ -0,0 +1,19 @@
+{ pkgs ? import <nixpkgs> {}
+, mode ? "mount"
+, fromFlake ? null
+, diskoFile
+, ... }@args:
+let
+ disko = import ./. { };
+ diskFormat =
+ if fromFlake != null
+ then (builtins.getFlake fromFlake) + "/${diskoFile}"
+ else import diskoFile;
+ diskoEval = if (mode == "create") then
+ disko.createScript diskFormat pkgs
+ else if (mode == "mount") then
+ disko.mountScript diskFormat pkgs
+ else
+ builtins.abort "invalid mode"
+ ;
+in diskoEval
diff --git a/default.nix b/default.nix
index 98f5213..8d91e7c 100644
--- a/default.nix
+++ b/default.nix
@@ -4,17 +4,26 @@ let
eval = cfg: lib.evalModules {
modules = lib.singleton {
# _file = toString input;
- imports = lib.singleton { topLevel.devices = cfg; };
+ imports = lib.singleton { devices = cfg; };
options = {
- topLevel = lib.mkOption {
- type = types.topLevel;
+ devices = lib.mkOption {
+ type = types.devices;
};
};
};
};
in {
types = types;
- create = cfg: (eval cfg).config.topLevel.create;
- mount = cfg: (eval cfg).config.topLevel.mount;
- config = cfg: (eval cfg).config.topLevel.config;
+ create = cfg: types.diskoLib.create (eval cfg).config.devices;
+ createScript = cfg: pkgs: pkgs.writeScript "disko-create" ''
+ export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}
+ ${types.diskoLib.create (eval cfg).config.devices}
+ '';
+ mount = cfg: types.diskoLib.mount (eval cfg).config.devices;
+ mountScript = cfg: pkgs: pkgs.writeScript "disko-mount" ''
+ export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}
+ ${types.diskoLib.mount (eval cfg).config.devices}
+ '';
+ config = cfg: { imports = types.diskoLib.config (eval cfg).config.devices; };
+ packages = cfg: types.diskoLib.packages (eval cfg).config.devices;
}
diff --git a/disko b/disko
new file mode 100755
index 0000000..deb3cbd
--- /dev/null
+++ b/disko
@@ -0,0 +1,94 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+readonly libexec_dir="${0%/*}"
+
+# a file with the disko config
+declare disko_config
+
+# a flake uri, if present disko config is relative to the flake root
+declare from_flake
+
+# mount was chosen as the default mode because it's less destructive
+mode=mount
+nix_args=()
+
+showUsage() {
+ cat <<USAGE
+Usage: $0 [options] disk-config.nix
+
+Options:
+
+* -m, --mode mode
+ set the mode, either create or mount
+* -f, --flake uri
+ fetch the disko config relative to this flake's root
+* --arg name value
+ pass value to nix-build. can be used to set disk-names for example
+* --argstr name value
+ pass value to nix-build as string
+USAGE
+}
+
+abort() {
+ echo "aborted: $*" >&2
+ exit 1
+}
+
+## Main ##
+
+[[ $# -eq 0 ]] && {
+ showUsage
+ exit 1
+}
+
+while [[ $# -gt 0 ]]; do
+ case "$1" in
+ -m | --mode)
+ mode=$2
+ shift
+ ;;
+ -f | --flake)
+ from_flake="$2"
+ nix_args+=("--argstr" "fromFlake" "$2")
+ shift
+ ;;
+ --argstr | --arg)
+ nix_args+=("$1" "$2" "$3")
+ shift
+ shift
+ ;;
+ --help)
+ showUsage
+ exit 0
+ ;;
+ *)
+ if [ -z ${disko_config+x} ]; then
+ disko_config=$1
+ else
+ showUsage
+ exit 1
+ fi
+ ;;
+ esac
+ shift
+done
+
+if ! ([[ $mode = "create" ]] || [[ $mode = "mount" ]]); then
+ abort "mode must be either create or mount"
+fi
+
+if [[ -e "${disko_config}" ]]; then
+ nix_args+=("--arg" "diskoFile" "$disko_config")
+elif [[ -n "${from_flake+x}" ]]; then
+ nix_args+=("--argstr" "diskoFile" "$disko_config")
+else
+ abort "disko config must be an exising file of flake must be set"
+fi
+
+script=$(nix-build "${libexec_dir}"/cli.nix \
+ --argstr diskoFile "$disko_config" \
+ --argstr mode "$mode" \
+ "${nix_args[@]}"
+)
+exec "$script"
diff --git a/example/boot-raid1.nix b/example/boot-raid1.nix
index c930eb5..dfd2e6c 100644
--- a/example/boot-raid1.nix
+++ b/example/boot-raid1.nix
@@ -1,4 +1,4 @@
-{ disks ? [ "/dev/vdb" "/dev/vdc" ] }: {
+{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = {
one = {
type = "disk";
diff --git a/example/btrfs-subvolumes.nix b/example/btrfs-subvolumes.nix
index 9a22861..02ce2a4 100644
--- a/example/btrfs-subvolumes.nix
+++ b/example/btrfs-subvolumes.nix
@@ -1,4 +1,4 @@
-{ disks ? [ "/dev/vdb" ] }: {
+{ disks ? [ "/dev/vdb" ], ... }: {
disk = {
vdb = {
type = "disk";
diff --git a/example/complex.nix b/example/complex.nix
index 7ee9282..b3fb951 100644
--- a/example/complex.nix
+++ b/example/complex.nix
@@ -1,4 +1,4 @@
-{ disks ? [ "/dev/vdb" "/dev/vdc" ] }: {
+{ disks ? [ "/dev/vdb" "/dev/vdc" "/dev/vdd" ], ... }: {
disk = {
disk0 = {
type = "disk";
diff --git a/example/gpt-bios-compat.nix b/example/gpt-bios-compat.nix
index 72886a0..7275e26 100644
--- a/example/gpt-bios-compat.nix
+++ b/example/gpt-bios-compat.nix
@@ -1,5 +1,5 @@
# Example to create a bios compatible gpt partition
-{ disks ? [ "/dev/vdb" ] }: {
+{ disks ? [ "/dev/vdb" ], ... }: {
disk = {
vdb = {
device = builtins.elemAt disks 0;
diff --git a/example/luks-lvm.nix b/example/luks-lvm.nix
index fdaba8c..8ffb273 100644
--- a/example/luks-lvm.nix
+++ b/example/luks-lvm.nix
@@ -1,4 +1,4 @@
-{ disks ? [ "/dev/vdb" ] }: {
+{ disks ? [ "/dev/vdb" ], ... }: {
disk = {
vdb = {
type = "disk";
diff --git a/example/lvm-raid.nix b/example/lvm-raid.nix
index 9d0c9d7..8622238 100644
--- a/example/lvm-raid.nix
+++ b/example/lvm-raid.nix
@@ -1,4 +1,4 @@
-{ disks ? [ "/dev/vdb" "/dev/vdc" ] }: {
+{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = {
one = {
type = "disk";
diff --git a/example/mdadm.nix b/example/mdadm.nix
index 8093698..132ead5 100644
--- a/example/mdadm.nix
+++ b/example/mdadm.nix
@@ -1,4 +1,4 @@
-{ disks ? [ "/dev/vdb" "/dev/vdc" ] }: {
+{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = {
vdb = {
type = "disk";
diff --git a/example/simple-efi.nix b/example/simple-efi.nix
new file mode 100644
index 0000000..c69c847
--- /dev/null
+++ b/example/simple-efi.nix
@@ -0,0 +1,40 @@
+{ disks ? [ "/dev/vdb" ], ... }: {
+ disk = {
+ vdb = {
+ device = builtins.elemAt disks 0;
+ type = "disk";
+ content = {
+ type = "table";
+ format = "gpt";
+ partitions = [
+ {
+ type = "partition";
+ name = "ESP";
+ start = "1MiB";
+ end = "100MiB";
+ bootable = true;
+ content = {
+ type = "filesystem";
+ format = "vfat";
+ mountpoint = "/boot";
+ };
+ }
+ {
+ name = "root";
+ type = "partition";
+ start = "100MiB";
+ end = "100%";
+ part-type = "primary";
+ bootable = true;
+ content = {
+ type = "filesystem";
+ format = "ext4";
+ mountpoint = "/";
+ };
+ }
+ ];
+ };
+ };
+ };
+}
+
diff --git a/example/with-lib.nix b/example/with-lib.nix
new file mode 100644
index 0000000..e746f5b
--- /dev/null
+++ b/example/with-lib.nix
@@ -0,0 +1,35 @@
+# Example to create a bios compatible gpt partition
+{ disks ? [ "/dev/vdb" ], lib, ... }: {
+ disk = lib.traceValSeq (lib.genAttrs [ (lib.head disks) ] (device: {
+ device = device;
+ type = "disk";
+ content = {
+ type = "table";
+ format = "gpt";
+ partitions = [
+ {
+ name = "boot";
+ type = "partition";
+ start = "0";
+ end = "1M";
+ part-type = "primary";
+ flags = ["bios_grub"];
+ }
+ {
+ name = "root";
+ type = "partition";
+ # leave space for the grub aka BIOS boot
+ start = "1M";
+ end = "100%";
+ part-type = "primary";
+ bootable = true;
+ content = {
+ type = "filesystem";
+ format = "ext4";
+ mountpoint = "/";
+ };
+ }
+ ];
+ };
+ }));
+}
diff --git a/example/zfs-over-legacy.nix b/example/zfs-over-legacy.nix
index 9943278..974af35 100644
--- a/example/zfs-over-legacy.nix
+++ b/example/zfs-over-legacy.nix
@@ -1,4 +1,4 @@
-{ disks ? [ "/dev/vdb" "/dev/vdc" ] }: {
+{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = {
vdb = {
type = "disk";
diff --git a/example/zfs.nix b/example/zfs.nix
index 92ed688..59c3f24 100644
--- a/example/zfs.nix
+++ b/example/zfs.nix
@@ -1,4 +1,4 @@
-{ disks ? [ "/dev/vdb" "/dev/vdc" ] }: {
+{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disk = {
x = {
type = "disk";
diff --git a/flake.lock b/flake.lock
deleted file mode 100644
index d99ebe5..0000000
--- a/flake.lock
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- "nodes": {
- "nixpkgs": {
- "locked": {
- "lastModified": 1660646295,
- "narHash": "sha256-V4G+egGRc3elXPTr7QLJ7r7yrYed0areIKDiIAlMLC8=",
- "owner": "NixOS",
- "repo": "nixpkgs",
- "rev": "762b003329510ea855b4097a37511eb19c7077f0",
- "type": "github"
- },
- "original": {
- "owner": "NixOS",
- "ref": "nixos-unstable",
- "repo": "nixpkgs",
- "type": "github"
- }
- },
- "root": {
- "inputs": {
- "nixpkgs": "nixpkgs"
- }
- }
- },
- "root": "root",
- "version": 7
-}
diff --git a/flake.nix b/flake.nix
index cdc5a4c..dd065cf 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,12 +1,49 @@
{
description = "Description for the project";
- inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+ # don't lock to give precedence to a USB live-installer's registry
+ inputs.nixpkgs.url = "nixpkgs";
outputs = { self, nixpkgs, ... }: {
+ nixosModules.disko = import ./module.nix;
lib = import ./. {
inherit (nixpkgs) lib;
};
+ packages.x86_64-linux.disko = let
+ pkgs = nixpkgs.legacyPackages.x86_64-linux;
+ inherit (pkgs) lib;
+ inclFiles = {src, name}: files: lib.cleanSourceWith {
+ inherit src name;
+ filter = _path: _type: _type == "regular"
+ && lib.any (file: builtins.baseNameOf _path == file) files;
+ };
+ in derivation rec{
+ system = "x86_64-linux";
+ name = "disko";
+ builder = "/bin/sh";
+ PATH = "${pkgs.coreutils}/bin:${pkgs.gnused}/bin";
+ passAsFile = ["buildPhase"];
+ buildPhase = ''
+ mkdir -p $out/bin $out/share/disko
+ cp -r $src/* $out/share/disko
+ sed \
+ -e "s|libexec_dir=\".*\"|libexec_dir=\"$out/share/disko\"|" \
+ -e "s|#!/usr/bin/env.*|#!/usr/bin/env bash|" \
+ $src/disko > $out/bin/disko
+ chmod 755 $out/bin/disko
+ '';
+ args = ["-c" ". $buildPhasePath"];
+ src = inclFiles { inherit name; src = ./.; } [
+ "disko"
+ "cli.nix"
+ "default.nix"
+ "types.nix"
+ "options.nix"
+ ];
+ } // {
+ meta.description = "Format disks with nix-config";
+ };
+ packages.x86_64-linux.default = self.packages.x86_64-linux.disko;
checks.x86_64-linux = let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in
diff --git a/module.nix b/module.nix
new file mode 100644
index 0000000..611d681
--- /dev/null
+++ b/module.nix
@@ -0,0 +1,43 @@
+{ config, lib, pkgs, ... }:
+let
+ types = import ./types.nix { inherit lib; };
+ cfg = config.disko;
+in {
+ options.disko = {
+ devices = lib.mkOption {
+ type = types.devices;
+ };
+ enableConfig = lib.mkOption {
+ description = ''
+ configure nixos with the specified devices
+ should be true if the system is booted with those devices
+ should be false on an installer image etc.
+ '';
+ type = lib.types.bool;
+ default = true;
+ };
+ addScripts = lib.mkOption {
+ description = ''
+ add disko-create and disko-mount scripts to systemPackages.
+ '';
+ type = lib.types.bool;
+ default = true;
+ };
+ };
+ config = {
+ environment.systemPackages = (lib.optionals cfg.addScripts [
+ (pkgs.writers.writeDashBin "disko-create" ''
+ export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)}
+ ${types.diskoLib.create cfg.devices}
+ '')
+ (pkgs.writers.writeDashBin "disko-mount" ''
+ export PATH=${lib.makeBinPath (types.diskoLib.packages cfg.devices pkgs)}
+ ${types.diskoLib.mount cfg.devices}
+ '')
+ ]) ++ lib.optionals cfg.enableConfig (types.diskoLib.packages cfg.devices pkgs);
+
+ # Remember to add config keys here if they are added to types
+ fileSystems = lib.mkIf cfg.enableConfig (lib.mkMerge (lib.catAttrs "fileSystems" (types.diskoLib.config cfg.devices)));
+ boot = lib.mkIf cfg.enableConfig (lib.mkMerge (lib.catAttrs "boot" (types.diskoLib.config cfg.devices)));
+ };
+}
diff --git a/tests/boot-raid1.nix b/tests/boot-raid1.nix
index 6d0a563..bea9adb 100644
--- a/tests/boot-raid1.nix
+++ b/tests/boot-raid1.nix
@@ -2,7 +2,7 @@
, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest
}:
makeDiskoTest {
- disko-config = import ../example/boot-raid1.nix;
+ disko-config = ../example/boot-raid1.nix;
extraTestScript = ''
machine.succeed("test -b /dev/md/boot");
machine.succeed("mountpoint /boot");
diff --git a/tests/btrfs-subvolumes.nix b/tests/btrfs-subvolumes.nix
index e53cf34..1a62702 100644
--- a/tests/btrfs-subvolumes.nix
+++ b/tests/btrfs-subvolumes.nix
@@ -2,7 +2,7 @@
, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest
}:
makeDiskoTest {
- disko-config = import ../example/btrfs-subvolumes.nix;
+ disko-config = ../example/btrfs-subvolumes.nix;
extraTestScript = ''
machine.succeed("test -e /test");
machine.succeed("btrfs subvolume list / | grep -qs 'path test$'");
diff --git a/tests/cli.nix b/tests/cli.nix
new file mode 100644
index 0000000..24eb24c
--- /dev/null
+++ b/tests/cli.nix
@@ -0,0 +1,28 @@
+{ pkgs ? (import <nixpkgs> { })
+, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest
+}:
+makeDiskoTest {
+ disko-config = ../example/complex.nix;
+ extraConfig = {
+ fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this!
+ };
+ testMode = "cli";
+ extraTestScript = ''
+ machine.succeed("test -b /dev/zroot/zfs_testvolume");
+ machine.succeed("test -b /dev/md/raid1p1");
+
+
+ machine.succeed("mountpoint /zfs_fs");
+ machine.succeed("mountpoint /zfs_legacy_fs");
+ machine.succeed("mountpoint /ext4onzfs");
+ machine.succeed("mountpoint /ext4_on_lvm");
+ '';
+ enableOCR = true;
+ bootCommands = ''
+ machine.wait_for_text("Passphrase for")
+ machine.send_chars("secret\n")
+ '';
+ extraConfig = {
+ boot.kernelModules = [ "dm-raid" "dm-mirror" ];
+ };
+}
diff --git a/tests/complex.nix b/tests/complex.nix
index cd87b3b..5fe5efa 100644
--- a/tests/complex.nix
+++ b/tests/complex.nix
@@ -2,7 +2,7 @@
, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest
}:
makeDiskoTest {
- disko-config = import ../example/complex.nix;
+ disko-config = ../example/complex.nix;
extraConfig = {
fileSystems."/zfs_legacy_fs".options = [ "nofail" ]; # TODO find out why we need this!
};
diff --git a/tests/gpt-bios-compat.nix b/tests/gpt-bios-compat.nix
index d9317f9..e19c49a 100644
--- a/tests/gpt-bios-compat.nix
+++ b/tests/gpt-bios-compat.nix
@@ -2,7 +2,7 @@
, makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest
}:
makeDiskoTest {
- disko-config = import ../example/gpt-bios-compat.nix;
+ disko-config = ../example/gpt-bios-compat.nix;
extraTestScript = ''
machine.succeed("mountpoint /");
'';
diff --git a/tests/lib.nix b/tests/lib.nix
index fb9d1e9..b9e75dd 100644
--- a/tests/lib.nix
+++ b/tests/lib.nix
@@ -12,6 +12,7 @@
, grub-devices ? [ "nodev" ]
, efi ? true
, enableOCR ? false
+ , testMode ? "direct" # can be one of direct module cli
}:
let
lib = pkgs.lib;
@@ -21,13 +22,21 @@
inherit (pkgs) system;
};
disks = [ "/dev/vda" "/dev/vdb" "/dev/vdc" "/dev/vdd" "/dev/vde" "/dev/vdf" ];
- tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. { }).create (disko-config { disks = builtins.tail disks; }));
- tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. { }).mount (disko-config { disks = builtins.tail disks; }));
- tsp-config = (pkgs.callPackage ../. { }).config (disko-config { inherit disks; });
- num-disks = builtins.length (lib.attrNames (disko-config {}).disk);
+ tsp-create = pkgs.writeScript "create" ((pkgs.callPackage ../. { }).create (import disko-config { disks = builtins.tail disks; inherit lib; }));
+ tsp-mount = pkgs.writeScript "mount" ((pkgs.callPackage ../. { }).mount (import disko-config { disks = builtins.tail disks; inherit lib; }));
+ tsp-config = (pkgs.callPackage ../. { }).config (import disko-config { inherit disks; inherit lib; });
+ num-disks = builtins.length (lib.attrNames (import disko-config { inherit lib; }).disk);
installed-system = { modulesPath, ... }: {
imports = [
- tsp-config
+ (lib.optionalAttrs (testMode == "direct" || testMode == "cli") tsp-config)
+ (lib.optionalAttrs (testMode == "module") {
+ imports = [ ../module.nix ];
+ disko = {
+ addScripts = false;
+ enableConfig = true;
+ devices = import disko-config { inherit disks lib; };
+ };
+ })
(modulesPath + "/testing/test-instrumentation.nix")
(modulesPath + "/profiles/qemu-guest.nix")
(modulesPath + "/profiles/minimal.nix")
@@ -63,6 +72,21 @@
inherit enableOCR;
nodes.machine = { config, pkgs, modulesPath, ... }: {
imports = [
+ (lib.optionalAttrs (testMode == "module") {
+ imports = [ ../module.nix ];
+ disko = {
+ addScripts = true;
+ enableConfig = false;
+ devices = import disko-config { disks = builtins.tail disks; inherit lib; };
+ };
+ })
+ (lib.optionalAttrs (testMode == "cli") {
+ imports = [ (modulesPath + "/installer/cd-dvd/channel.nix") ];
+ system.extraDependencies = [
+ ((pkgs.callPackage ../. { }).createScript (import disko-config { disks = builtins.tail disks; inherit lib; }) pkgs)
+ ((pkgs.callPackage ../. { }).mountScript (import disko-config { disks = builtins.tail disks; inherit lib; }) pkgs)
+ ];
+ })
(modulesPath + "/profiles/base.nix")
(modulesPath + "/profiles/minimal.nix")
extraConfig
@@ -97,9 +121,25 @@
machine.start()
machine.succeed