mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 13:03:28 +01:00
Compare commits
48
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0fe8a3b4b | ||
|
|
c8a0e78d86 | ||
|
|
31fe7eda26 | ||
|
|
a5c4f2ab72 | ||
|
|
bafad29f89 | ||
|
|
49c1bc1b34 | ||
|
|
4073ff2f48 | ||
|
|
f64ab1525b | ||
|
|
8246829f2e | ||
|
|
545aba0296 | ||
|
|
3db2f04765 | ||
|
|
d5ad4485e6 | ||
|
|
2bf3421f7f | ||
|
|
79264292b7 | ||
|
|
16b74a1e30 | ||
|
|
da6109c917 | ||
|
|
83c4da299c | ||
|
|
8fd2d6c750 | ||
|
|
7f1857b315 | ||
|
|
dfa4d1b9c3 | ||
|
|
17d08c65c2 | ||
|
|
6d06f63fc0 | ||
|
|
d74db625a5 | ||
|
|
a4f7deb49f | ||
|
|
58d6e5a83f | ||
|
|
a894f2811e | ||
|
|
df522e787f | ||
|
|
58e72c6ec2 | ||
|
|
cec44d77d9 | ||
|
|
ec7c109a4f | ||
|
|
490c0d6bd1 | ||
|
|
85555d27de | ||
|
|
6ca7c94d6a | ||
|
|
14afb10129 | ||
|
|
a956a7c255 | ||
|
|
6bb82b77ce | ||
|
|
06fb9283ca | ||
|
|
69265ccde5 | ||
|
|
cbc1f418d0 | ||
|
|
aa5d53aee8 | ||
|
|
c7e0b00007 | ||
|
|
aba0ae38df | ||
|
|
b5cfd59e9a | ||
|
|
c4fe2d108b | ||
|
|
78d6a1365c | ||
|
|
8d78963819 | ||
|
|
b5d1320ebc | ||
|
|
7b63642358 |
No files matched your search
@@ -1,22 +0,0 @@
|
||||
name: "Publish a flake to flakestry"
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v?[0-9]+.[0-9]+.[0-9]+"
|
||||
- "v?[0-9]+.[0-9]+"
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: "The existing tag to publish"
|
||||
type: "string"
|
||||
required: true
|
||||
jobs:
|
||||
publish-flake:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
id-token: "write"
|
||||
contents: "read"
|
||||
steps:
|
||||
- uses: flakestry/flakestry-publish@main
|
||||
with:
|
||||
version: "${{ inputs.tag || github.ref_name }}"
|
||||
@@ -11,11 +11,11 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
- name: Install Nix
|
||||
uses: cachix/install-nix-action@v31
|
||||
- name: Update flake.lock
|
||||
uses: DeterminateSystems/update-flake-lock@v24
|
||||
uses: DeterminateSystems/update-flake-lock@v27
|
||||
with:
|
||||
pr-labels: |
|
||||
merge-queue
|
||||
@@ -4,3 +4,6 @@ result-*
|
||||
|
||||
# Created by the NixOS interactive test driver
|
||||
.nixos-test-history
|
||||
|
||||
# Created by `:bl` in `nix repl`
|
||||
repl-result-out
|
||||
@@ -12,6 +12,43 @@ way to help us fix issues quickly. Check out
|
||||
For more information on how to run and debug tests, check out
|
||||
[Running and debugging tests](./docs/testing.md).
|
||||
|
||||
## Finding and Running Tests
|
||||
|
||||
### Listing All Available Tests
|
||||
|
||||
To see all available tests in the project:
|
||||
|
||||
```bash
|
||||
# List all test files
|
||||
ls tests/*.nix | grep -v default.nix
|
||||
|
||||
# List all tests using nix eval
|
||||
nix eval --apply builtins.attrNames .#checks.x86_64-linux --json | jq -r '.[]' | sort
|
||||
```
|
||||
|
||||
### Running Tests
|
||||
|
||||
```bash
|
||||
# Run all tests and checks
|
||||
nix-fast-build
|
||||
|
||||
# Run a specific test by name
|
||||
nix build .#checks.x86_64-linux.simple-efi -L
|
||||
|
||||
# Run tests matching a pattern
|
||||
nix eval --apply 'checks: builtins.filter (name: builtins.match ".*luks.*" name != null) (builtins.attrNames checks)' .#checks.x86_64-linux --json | jq -r '.[]' | xargs -I {} echo nix build .#checks.x86_64-linux.{} -L
|
||||
```
|
||||
|
||||
### Understanding Test Structure
|
||||
|
||||
Each test file in `tests/` corresponds to an example configuration in `example/`:
|
||||
- `tests/simple-efi.nix` tests `example/simple-efi.nix`
|
||||
- `tests/luks-lvm.nix` tests `example/luks-lvm.nix`
|
||||
- etc.
|
||||
|
||||
Tests use NixOS's `make-test-python.nix` framework to create VMs that actually partition disks and verify the configurations work correctly.
|
||||
|
||||
|
||||
## How to find issues to work on
|
||||
|
||||
If you're looking for a low-hanging fruit, check out
|
||||
|
||||
@@ -17,11 +17,14 @@ let
|
||||
|
||||
hasDiskoFile = diskoFile != null;
|
||||
|
||||
hasDiskoConfigFlake =
|
||||
hasDiskoFile || lib.hasAttrByPath [ "diskoConfigurations" flakeAttr ] (builtins.getFlake flake);
|
||||
|
||||
diskoAttr =
|
||||
(
|
||||
if noDeps then
|
||||
(
|
||||
if hasDiskoFile then
|
||||
if hasDiskoFile || hasDiskoConfigFlake then
|
||||
{
|
||||
destroy = "_cliDestroyNoDeps";
|
||||
format = "_cliFormatNoDeps";
|
||||
@@ -50,7 +53,7 @@ let
|
||||
}
|
||||
else
|
||||
(
|
||||
if hasDiskoFile then
|
||||
if hasDiskoFile || hasDiskoConfigFlake then
|
||||
{
|
||||
destroy = "_cliDestroy";
|
||||
format = "_cliFormat";
|
||||
@@ -79,9 +82,6 @@ let
|
||||
}
|
||||
).${mode};
|
||||
|
||||
hasDiskoConfigFlake =
|
||||
hasDiskoFile || lib.hasAttrByPath [ "diskoConfigurations" flakeAttr ] (builtins.getFlake flake);
|
||||
|
||||
hasDiskoModuleFlake = lib.hasAttrByPath [
|
||||
"nixosConfigurations"
|
||||
flakeAttr
|
||||
|
||||
@@ -127,7 +127,7 @@ fi
|
||||
echo "disko version $DISKO_VERSION"
|
||||
|
||||
nixBuild() {
|
||||
if command -v nom-build > /dev/null; then
|
||||
if command -v nom-build > /dev/null && [ -t 1 ]; then
|
||||
nom-build "$@"
|
||||
else
|
||||
nix-build "$@"
|
||||
|
||||
+2
-2
@@ -164,7 +164,7 @@ cleanupMountPoint() {
|
||||
}
|
||||
|
||||
nixBuild() {
|
||||
if command -v nom-build > /dev/null; then
|
||||
if command -v nom-build > /dev/null && [ -t 1 ]; then
|
||||
nom-build "$@"
|
||||
else
|
||||
nix-build "$@"
|
||||
@@ -256,7 +256,7 @@ main() {
|
||||
if [[ ! -f "${mountPoint}/nix/var/nix/db/db.sqlite" ]]; then
|
||||
echo "Copying store paths" >&2
|
||||
mkdir -p "${mountPoint}/nix/store"
|
||||
xargs cp --recursive --target "${mountPoint}/nix/store" < "${closure_info}/store-paths"
|
||||
xargs xcp --recursive --target-directory "${mountPoint}/nix/store" < "${closure_info}/store-paths"
|
||||
echo "Loading nix database" >&2
|
||||
NIX_STATE_DIR=${mountPoint}/nix/var/nix nix-store --load-db < "${closure_info}/registration"
|
||||
fi
|
||||
|
||||
+74
-8
@@ -1,11 +1,9 @@
|
||||
# Generating Disk Images with Secrets Included using Disko
|
||||
|
||||
Using Disko on NixOS allows you to efficiently create `.raw` VM images from a
|
||||
system configuration. The generated image can be used as a VM or directly
|
||||
written to a physical drive to create a bootable disk. Follow the steps below to
|
||||
generate disk images:
|
||||
Using Disko on NixOS allows you to efficiently create `.raw` disk images from a system configuration.
|
||||
Follow the steps below to generate disk images:
|
||||
|
||||
## Generating the `.raw` VM Image
|
||||
## Generating the `.raw` Image
|
||||
|
||||
1. **Create a NixOS configuration that includes the disko and the disk
|
||||
configuration of your choice**
|
||||
@@ -24,16 +22,29 @@ In the this example we create a flake containing a nixos configuration for
|
||||
disko.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
outputs = { self, disko, nixpkgs }: {
|
||||
outputs = { self, disko, nixpkgs, ... }: {
|
||||
nixosConfigurations.myhost = nixpkgs.lib.nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
modules = [
|
||||
# You can get this file from here: https://github.com/nix-community/disko/blob/master/example/simple-efi.nix
|
||||
./simple-efi.nix
|
||||
disko.nixosModules.disko
|
||||
({ config, ... }: {
|
||||
({ config, modulesPath, ... }: {
|
||||
imports = [
|
||||
# include this line to boot to boot the image inside a VM
|
||||
# "${modulesPath}/profiles/qemu-guest.nix"
|
||||
# On other hardware, you may need a hardware-configuration.nix as generated by nixos-generate-config or use nixos-facter (https://github.com/numtide/nixos-facter)
|
||||
# ./hardware-configuration.nix
|
||||
];
|
||||
|
||||
# Optional. Useful for testing
|
||||
# users.users.root.initialPassword = "root";
|
||||
|
||||
boot.loader.grub.efiSupport = lib.mkDefault true;
|
||||
boot.loader.grub.efiInstallAsRemovable = lib.mkDefault true;
|
||||
|
||||
# shut up state version warning
|
||||
system.stateVersion = config.system.nixos.version;
|
||||
system.stateVersion = config.system.nixos.release;
|
||||
# Adjust this to your liking.
|
||||
# WARNING: if you set a too low value the image might be not big enough to contain the nixos installation
|
||||
disko.devices.disk.main.imageSize = "10G";
|
||||
@@ -141,3 +152,58 @@ In the this example we create a flake containing a nixos configuration for
|
||||
|
||||
By following these instructions and understanding the process, you can smoothly
|
||||
generate disk images with Disko for your NixOS system configurations.
|
||||
|
||||
## Test the image inside a VM
|
||||
|
||||
Make sure you uncommented the `"${modulesPath}/profiles/qemu-guest.nix"` import in the example above!
|
||||
|
||||
Write the following script to `qemu.nix`. Note that it expects an UEFI compatible image!
|
||||
|
||||
```
|
||||
with import <nixpkgs> {};
|
||||
|
||||
writeShellApplication {
|
||||
name = "test-image";
|
||||
runtimeInputs = [ qemu ];
|
||||
text = ''
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: $0 <path-to-boot-image>"
|
||||
exit 1
|
||||
fi
|
||||
tmpFile=$(mktemp /tmp/test-image.XXXXXX)
|
||||
trap 'rm -f $tmpFile' EXIT
|
||||
cp "$1" "$tmpFile"
|
||||
qemu-system-x86_64 \
|
||||
-enable-kvm \
|
||||
-m 2G \
|
||||
-cpu max \
|
||||
-smp 2 \
|
||||
-netdev user,id=net0,hostfwd=tcp::2222-:22 \
|
||||
-device virtio-net-pci,netdev=net0 \
|
||||
-drive if=pflash,format=raw,readonly=on,file=${OVMF.firmware} \
|
||||
-drive if=pflash,format=raw,readonly=on,file=${OVMF.variables} \
|
||||
-drive "if=virtio,format=raw,file=$tmpFile"
|
||||
'';
|
||||
}
|
||||
```
|
||||
|
||||
This command will run a qemu vm with your image:
|
||||
|
||||
```
|
||||
$(nix-build ./qemu.nix)/bin/test-image ./main.raw
|
||||
```
|
||||
|
||||
Replace `main.raw` with the image that you build!
|
||||
|
||||
Tip: You can customize memory (`-m` flag) or cpu (`-smp` flag) available to the VM to your liking.
|
||||
|
||||
## Build the image inside the nix sandbox
|
||||
|
||||
Instead of the diskoImagesScript, we can also build the image inside the nix store.
|
||||
This approach is slower because it requires copying the image after the build and
|
||||
we also don't have a secure way to embed secrets this way.
|
||||
|
||||
```
|
||||
nix build .#nixosConfigurations.myhost.config.system.build.diskoImages
|
||||
ls -a ./result/main.raw
|
||||
```
|
||||
+13
-2
@@ -197,8 +197,19 @@ Add this to your flake.nix output:
|
||||
```nix
|
||||
# `self` here is referring to the flake `self`, you may need to pass it using `specialArgs` or define your NixOS installer configuration
|
||||
# in the flake.nix itself to get direct access to the `self` flake variable.
|
||||
{ pkgs, self, ... }:
|
||||
{ lib, pkgs, self, ... }:
|
||||
let
|
||||
flakeOutPaths =
|
||||
let
|
||||
collector =
|
||||
parent:
|
||||
map (
|
||||
child:
|
||||
[ child.outPath ] ++ (if child ? inputs && child.inputs != { } then (collector child) else [ ])
|
||||
) (lib.attrValues parent.inputs);
|
||||
in
|
||||
lib.unique (lib.flatten (collector self));
|
||||
|
||||
dependencies = [
|
||||
self.nixosConfigurations.your-machine.config.system.build.toplevel
|
||||
self.nixosConfigurations.your-machine.config.system.build.diskoScript
|
||||
@@ -210,7 +221,7 @@ let
|
||||
self.nixosConfigurations.your-machine.pkgs.perlPackages.FileSlurp
|
||||
|
||||
(self.nixosConfigurations.your-machine.pkgs.closureInfo { rootPaths = [ ]; }).drvPath
|
||||
] ++ builtins.map (i: i.outPath) (builtins.attrValues self.inputs);
|
||||
] ++ flakeOutPaths;
|
||||
|
||||
closureInfo = pkgs.closureInfo { rootPaths = dependencies; };
|
||||
in
|
||||
|
||||
+42
-141
@@ -23,7 +23,7 @@
|
||||
content = {
|
||||
type = "bcachefs";
|
||||
# This refers to a filesystem in the `bcachefs_filesystems` attrset below.
|
||||
filesystem = "unmounted_subvolumes_in_multi";
|
||||
filesystem = "mounted_subvolumes_in_multi";
|
||||
label = "group_a.vdb2";
|
||||
extraFormatArgs = [
|
||||
"--discard"
|
||||
@@ -44,7 +44,7 @@
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "bcachefs";
|
||||
filesystem = "unmounted_subvolumes_in_multi";
|
||||
filesystem = "mounted_subvolumes_in_multi";
|
||||
label = "group_a.vdc1";
|
||||
extraFormatArgs = [
|
||||
"--discard"
|
||||
@@ -65,7 +65,7 @@
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "bcachefs";
|
||||
filesystem = "unmounted_subvolumes_in_multi";
|
||||
filesystem = "mounted_subvolumes_in_multi";
|
||||
label = "group_b.vdd1";
|
||||
extraFormatArgs = [
|
||||
"--force"
|
||||
@@ -79,87 +79,6 @@
|
||||
vde = {
|
||||
device = "/dev/vde";
|
||||
type = "disk";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
vde1 = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "bcachefs";
|
||||
filesystem = "mounted_subvolumes_in_multi";
|
||||
label = "group_a.vde1";
|
||||
extraFormatArgs = [
|
||||
"--discard"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
vdf = {
|
||||
device = "/dev/vdf";
|
||||
type = "disk";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
vdf1 = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "bcachefs";
|
||||
filesystem = "mounted_subvolumes_in_multi";
|
||||
label = "group_a.vdf1";
|
||||
extraFormatArgs = [
|
||||
"--discard"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
vdg = {
|
||||
device = "/dev/vdg";
|
||||
type = "disk";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
vdd1 = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "bcachefs";
|
||||
filesystem = "mounted_subvolumes_in_multi";
|
||||
label = "group_b.vdg1";
|
||||
extraFormatArgs = [
|
||||
"--force"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
vdh = {
|
||||
device = "/dev/vdh";
|
||||
type = "disk";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
vdd1 = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "bcachefs";
|
||||
filesystem = "no_reliance_on_external_subvolume";
|
||||
label = "group_a.vdh1";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
vdi = {
|
||||
device = "/dev/vdi";
|
||||
type = "disk";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
@@ -168,7 +87,7 @@
|
||||
content = {
|
||||
type = "bcachefs";
|
||||
filesystem = "relies_on_external_subvolume";
|
||||
label = "group_a.vdi1";
|
||||
label = "group_a.vde1";
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -177,72 +96,54 @@
|
||||
};
|
||||
|
||||
bcachefs_filesystems = {
|
||||
# Example showing unmounted subvolumes in a multi-disk configuration.
|
||||
unmounted_subvolumes_in_multi = {
|
||||
# Example showing mounted subvolumes in a multi-disk configuration.
|
||||
mounted_subvolumes_in_multi = {
|
||||
type = "bcachefs_filesystem";
|
||||
passwordFile = "/tmp/secret.key";
|
||||
extraFormatArgs = [
|
||||
"--compression=lz4"
|
||||
"--background_compression=lz4"
|
||||
];
|
||||
subvolumes = {
|
||||
# Subvolume name is different from mountpoint.
|
||||
"subvolumes/root" = {
|
||||
mountpoint = "/";
|
||||
mountOptions = [
|
||||
"verbose"
|
||||
];
|
||||
};
|
||||
# Subvolume name is the same as the mountpoint.
|
||||
"subvolumes/home" = {
|
||||
mountpoint = "/home";
|
||||
};
|
||||
# Nested subvolume doesn't need a mountpoint as its parent is mounted.
|
||||
"subvolumes/home/user" = {
|
||||
};
|
||||
# Parent is not mounted so the mountpoint must be set.
|
||||
"subvolumes/nix" = {
|
||||
mountpoint = "/nix";
|
||||
};
|
||||
# This subvolume will be created but not mounted.
|
||||
"subvolumes/test" = {
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# Example showing a bcachefs filesystem without subvolumes,
|
||||
# which relies on a subvolume in another filesystem being mounted
|
||||
# and uses a hard-coded UUID.
|
||||
relies_on_external_subvolume = {
|
||||
type = "bcachefs_filesystem";
|
||||
mountpoint = "/home/Documents";
|
||||
extraFormatArgs = [
|
||||
"--compression=lz4"
|
||||
"--background_compression=lz4"
|
||||
];
|
||||
mountOptions = [
|
||||
"verbose"
|
||||
];
|
||||
mountpoint = "/";
|
||||
subvolumes = {
|
||||
"subvolumes/rootfs" = { };
|
||||
"subvolumes/home" = { };
|
||||
"subvolumes/home/user" = { };
|
||||
"subvolumes/nix" = { };
|
||||
"subvolumes/test" = { };
|
||||
};
|
||||
uuid = "64e50034-ebe2-eaf8-1f93-cf56266a8d86";
|
||||
};
|
||||
|
||||
# # Example showing mounted subvolumes in a multi-disk configuration (not yet working).
|
||||
# mounted_subvolumes_in_multi = {
|
||||
# type = "bcachefs_filesystem";
|
||||
# passwordFile = "/tmp/secret.key";
|
||||
# extraFormatArgs = [
|
||||
# "--compression=lz4"
|
||||
# "--background_compression=lz4"
|
||||
# ];
|
||||
# mountOptions = [
|
||||
# "verbose"
|
||||
# ];
|
||||
# subvolumes = {
|
||||
# # Subvolume name is different from mountpoint
|
||||
# "foo" = {
|
||||
# mountpoint = "/bar";
|
||||
# };
|
||||
# # Subvolume name is the same as the mountpoint
|
||||
# "home" = {
|
||||
# mountpoint = "/home";
|
||||
# };
|
||||
# # Sub(sub)volume doesn't need a mountpoint as its parent is mounted
|
||||
# "home/user" = {
|
||||
# };
|
||||
# # Parent is not mounted so the mountpoint must be set
|
||||
# "nix" = {
|
||||
# mountpoint = "/nix";
|
||||
# };
|
||||
# # This subvolume will be created but not mounted
|
||||
# "test" = {
|
||||
# };
|
||||
# };
|
||||
# };
|
||||
|
||||
# Example showing another bcachefs filesystem.
|
||||
no_reliance_on_external_subvolume = {
|
||||
type = "bcachefs_filesystem";
|
||||
mountpoint = "/sometestdir";
|
||||
};
|
||||
|
||||
# # Example showing another bcachefs filesystem that relies on a subvolume
|
||||
# # in another filesystem being mounted (not yet working).
|
||||
# relies_on_external_subvolume = {
|
||||
# type = "bcachefs_filesystem";
|
||||
# mountpoint = "/home/somedir/vdf1";
|
||||
# };
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
boot = {
|
||||
size = "1M";
|
||||
type = "EF02"; # for grub MBR
|
||||
attributes = [ 0 ]; # partition attribute
|
||||
};
|
||||
root = {
|
||||
size = "100%";
|
||||
|
||||
@@ -244,7 +244,7 @@
|
||||
type = "topology";
|
||||
vdev = [
|
||||
{
|
||||
# This syntax expects a disk called 'data3' with a gpt partition called 'zfs'.
|
||||
# This syntax expects a disk called 'data1' with a gpt partition called 'zfs'.
|
||||
members = [ "data1" ];
|
||||
# It's also possible to use the full path of the device or partition
|
||||
# members = [ "/dev/disk/by-id/wwn-0x5000c500af8b2a14" ];
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
{ lib, ... }:
|
||||
{
|
||||
options.flake.diskoConfigurations = lib.mkOption {
|
||||
type = lib.types.lazyAttrsOf lib.types.raw;
|
||||
default = { };
|
||||
description = "Instantiated Disko configurations. Used by `disko` and `disko-install`.";
|
||||
example = {
|
||||
my-pc = {
|
||||
disko.devices = {
|
||||
disk = {
|
||||
my-disk = {
|
||||
device = "/dev/sda";
|
||||
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 = "ext4";
|
||||
mountpoint = "/";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Generated
+3
-3
@@ -2,11 +2,11 @@
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1744868846,
|
||||
"narHash": "sha256-5RJTdUHDmj12Qsv7XOhuospjAjATNiTMElplWnJE9Hs=",
|
||||
"lastModified": 1752596105,
|
||||
"narHash": "sha256-lFNVsu/mHLq3q11MuGkMhUUoSXEdQjCHvpReaGP1S2k=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "ebe4301cbd8f81c4f8d3244b3632338bbeb6d49c",
|
||||
"rev": "dab3a6e781554f965bde3def0aa2fda4eb8f1708",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
{
|
||||
nixosModules.default = self.nixosModules.disko; # convention
|
||||
nixosModules.disko = ./module.nix;
|
||||
flakeModule = self.flakeModules.default;
|
||||
flakeModules.default = self.flakeModules.disko;
|
||||
flakeModules.disko = ./flake-module.nix;
|
||||
lib = diskoLib;
|
||||
packages = forAllSystems (
|
||||
system:
|
||||
|
||||
+41
-15
@@ -23,21 +23,40 @@ let
|
||||
lib.mkOptionType {
|
||||
name = "subType";
|
||||
description = "one of ${lib.concatStringsSep "," (lib.attrNames types)}";
|
||||
check =
|
||||
x:
|
||||
if x ? type then
|
||||
types.${x.type}.check x
|
||||
else
|
||||
throw "No type option set in:\n${lib.generators.toPretty { } x}";
|
||||
check = x: lib.isAttrs x;
|
||||
merge =
|
||||
loc:
|
||||
lib.foldl' (
|
||||
_res: def:
|
||||
types.${def.value.type}.merge loc [
|
||||
loc: defs:
|
||||
let
|
||||
evaled = lib.evalModules {
|
||||
modules =
|
||||
[
|
||||
{
|
||||
freeformType = lib.types.lazyAttrsOf lib.types.raw;
|
||||
options.type = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
};
|
||||
}
|
||||
]
|
||||
++ map (
|
||||
{ value, file }:
|
||||
{
|
||||
_file = file;
|
||||
config = value;
|
||||
}
|
||||
) defs;
|
||||
};
|
||||
inherit (evaled.config) type;
|
||||
in
|
||||
types.${type}.merge loc (
|
||||
[
|
||||
# we add a dummy root parent node to render documentation
|
||||
(lib.recursiveUpdate { value._module.args = extraArgs; } def)
|
||||
{
|
||||
file = "";
|
||||
value._module.args = extraArgs;
|
||||
}
|
||||
]
|
||||
) { };
|
||||
++ defs
|
||||
);
|
||||
nestedTypes = types;
|
||||
};
|
||||
|
||||
@@ -875,9 +894,15 @@ let
|
||||
umount -Rv "${rootMountPoint}" || :
|
||||
|
||||
# shellcheck disable=SC2043,2041
|
||||
for dev in ${toString (lib.catAttrs "device" (lib.attrValues devices.disk))}; do
|
||||
for dev in ${
|
||||
toString (
|
||||
lib.catAttrs "device" (lib.attrValues (lib.filterAttrs (name: disk: disk.destroy) devices.disk))
|
||||
)
|
||||
};
|
||||
do
|
||||
$BASH ${../disk-deactivate}/disk-deactivate "$dev"
|
||||
done
|
||||
|
||||
'';
|
||||
};
|
||||
_destroy = lib.mkOption {
|
||||
@@ -888,7 +913,8 @@ let
|
||||
'';
|
||||
default =
|
||||
let
|
||||
selectedDisks = lib.escapeShellArgs (lib.catAttrs "device" (lib.attrValues devices.disk));
|
||||
disksToWipe = lib.attrValues (lib.filterAttrs (name: disk: disk.destroy) devices.disk);
|
||||
selectedDisks = lib.escapeShellArgs (lib.catAttrs "device" disksToWipe);
|
||||
in
|
||||
''
|
||||
if [ "$1" != "--yes-wipe-all-disks" ]; then
|
||||
@@ -913,7 +939,7 @@ let
|
||||
umount -Rv "${rootMountPoint}" || :
|
||||
|
||||
# shellcheck disable=SC2043,2041
|
||||
for dev in ${selectedDisks}; do
|
||||
for dev in ${toString (lib.catAttrs "device" disksToWipe)}; do
|
||||
$BASH ${../disk-deactivate}/disk-deactivate "$dev"
|
||||
done
|
||||
'';
|
||||
|
||||
@@ -43,7 +43,10 @@ let
|
||||
++ (lib.optional configSupportsZfs "zfs")
|
||||
++ cfg.extraRootModules;
|
||||
kernel = pkgs.aggregateModules (
|
||||
[ cfg.kernelPackages.kernel ]
|
||||
[
|
||||
cfg.kernelPackages.kernel
|
||||
]
|
||||
++ lib.optional (cfg.kernelPackages.kernel ? modules) cfg.kernelPackages.kernel.modules
|
||||
++ lib.optional (
|
||||
lib.elem "zfs" cfg.extraRootModules || configSupportsZfs
|
||||
) cfg.kernelPackages.${config.boot.zfs.package.kernelModuleAttribute}
|
||||
@@ -92,6 +95,7 @@ let
|
||||
util-linux
|
||||
findutils
|
||||
kmod
|
||||
xcp
|
||||
]
|
||||
++ cfg.extraDependencies;
|
||||
preVM = ''
|
||||
@@ -136,13 +140,14 @@ let
|
||||
|
||||
installer = lib.optionalString cfg.copyNixStore ''
|
||||
${binfmtSetup}
|
||||
unset NIX_REMOTE
|
||||
# populate nix db, so nixos-install doesn't complain
|
||||
export NIX_STATE_DIR=${systemToInstall.config.disko.rootMountPoint}/nix/var/nix
|
||||
nix-store --load-db < "${closureInfo}/registration"
|
||||
|
||||
# We copy files with cp because `nix copy` seems to have a large memory leak
|
||||
mkdir -p ${systemToInstall.config.disko.rootMountPoint}/nix/store
|
||||
time xargs cp --recursive --target ${systemToInstall.config.disko.rootMountPoint}/nix/store < ${closureInfo}/store-paths
|
||||
xargs xcp --recursive --target-directory ${systemToInstall.config.disko.rootMountPoint}/nix/store < ${closureInfo}/store-paths
|
||||
|
||||
${systemToInstall.config.system.build.nixos-install}/bin/nixos-install --root ${systemToInstall.config.disko.rootMountPoint} --system ${systemToInstall.config.system.build.toplevel} --keep-going --no-channel-copy -v --no-root-password --option binary-caches ""
|
||||
umount -Rv ${lib.escapeShellArg systemToInstall.config.disko.rootMountPoint}
|
||||
@@ -266,7 +271,7 @@ in
|
||||
# shellcheck disable=SC2016
|
||||
QEMU_OPTS=${lib.escapeShellArg QEMU_OPTS}
|
||||
# replace quoted $out with the actual path
|
||||
QEUM_OPTS=''${QEMU_OPTS//\$out/$out}
|
||||
QEMU_OPTS=''${QEMU_OPTS//\$out/$out}
|
||||
QEMU_OPTS+=" -m $build_memory -object memory-backend-memfd,id=mem,size=''${build_memory}M,share=on -machine memory-backend=mem"
|
||||
export QEMU_OPTS
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
default = ''
|
||||
# Write device arguments to temporary directory for bcachefs_filesystem.
|
||||
{
|
||||
printf '%s\n' '--label="${config.label}"';
|
||||
printf '%s\n' '--label=${config.label}';
|
||||
${lib.concatMapStrings (args: ''printf '%s\n' '${args}';'') config.extraFormatArgs}
|
||||
printf '%s\n' '${config.device}';
|
||||
} >> "$disko_devices_dir/bcachefs-${lib.escapeShellArg config.filesystem}";
|
||||
|
||||
@@ -113,10 +113,7 @@
|
||||
mountpoint = lib.mkOption {
|
||||
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname;
|
||||
default = null;
|
||||
description = ''
|
||||
Path to mount the subvolume to.
|
||||
DO NOT USE. Currently not working.
|
||||
'';
|
||||
description = "Path to mount the subvolume to.";
|
||||
example = "/";
|
||||
};
|
||||
};
|
||||
@@ -126,7 +123,19 @@
|
||||
default = { };
|
||||
description = "List of subvolumes to define.";
|
||||
example = {
|
||||
"subvolumes/home" = { };
|
||||
"subvolumes/root" = {
|
||||
mountpoint = "/";
|
||||
extraFormatArgs = [
|
||||
"--compression=lz4"
|
||||
"--background_compression=lz4"
|
||||
];
|
||||
mountOptions = [
|
||||
"verbose"
|
||||
];
|
||||
};
|
||||
"subvolumes/home" = {
|
||||
mountpoint = "/home";
|
||||
};
|
||||
};
|
||||
};
|
||||
_parent = lib.mkOption {
|
||||
@@ -291,11 +300,10 @@
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
# @todo Check that this implementation is correct:
|
||||
default =
|
||||
(lib.optional (config.mountpoint != null) {
|
||||
fileSystems.${config.mountpoint} = {
|
||||
device = "UUID=${config.uuid}";
|
||||
device = "/dev/disk/by-uuid/${config.uuid}";
|
||||
fsType = "bcachefs";
|
||||
options = lib.unique ([ "X-mount.mkdir" ] ++ config.mountOptions);
|
||||
neededForBoot = true;
|
||||
@@ -303,7 +311,7 @@
|
||||
})
|
||||
++ (map (subvolume: {
|
||||
fileSystems.${subvolume.mountpoint} = {
|
||||
device = "UUID=${config.uuid}";
|
||||
device = "/dev/disk/by-uuid/${config.uuid}";
|
||||
fsType = "bcachefs";
|
||||
options = lib.unique (
|
||||
[
|
||||
|
||||
@@ -22,6 +22,11 @@
|
||||
type = diskoLib.optionTypes.absolute-pathname; # TODO check if subpath of /dev ? - No! eg: /.swapfile
|
||||
description = "Device path";
|
||||
};
|
||||
destroy = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
description = "If false, disko will not wipe or destroy this disk's contents during the destroy stage";
|
||||
};
|
||||
imageName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = config.name;
|
||||
|
||||
@@ -57,6 +57,27 @@ in
|
||||
or a fully specified GUID (see https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs).
|
||||
'';
|
||||
};
|
||||
attributes = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.int;
|
||||
default = [ ];
|
||||
description = ''
|
||||
GPT partition entry attributes, according to UEFI specification
|
||||
2.10 (see https://uefi.org/specs/UEFI/2.10_A/05_GUID_Partition_Table_Format.html#defined-gpt-partition-entry-attributes)
|
||||
and `sgdisk`s man page:
|
||||
|
||||
- 0: Required Partition (`sgdisk`: system partition)
|
||||
- 1: No Block IO Protocol (`sgdisk`: hide from EFI)
|
||||
- 2: Legacy BIOS Bootable
|
||||
- 3-47: Undefined and must be zero, reserved for future use
|
||||
- 48-63: Reserved for GUID specific use. The use of these bits
|
||||
will vary depending on the partition type
|
||||
|
||||
`sgdisk` describes some of the GUID-specific bits this way:
|
||||
- 60: read only
|
||||
- 62: hidden
|
||||
- 63: do not automount
|
||||
'';
|
||||
};
|
||||
device = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default =
|
||||
@@ -268,6 +289,14 @@ in
|
||||
}" \
|
||||
--change-name="${toString partition._index}:${partition.label}" \
|
||||
--typecode=${toString partition._index}:${partition.type} \
|
||||
--attributes=${toString partition._index}:=:0 \
|
||||
${
|
||||
lib.concatStringsSep " \\\n" (
|
||||
builtins.map (bitNumber: "--attributes=${toString partition._index}:set:${toString bitNumber}") (
|
||||
lib.unique partition.attributes
|
||||
)
|
||||
)
|
||||
} \
|
||||
"${config.device}" \
|
||||
'';
|
||||
createArgs = ''
|
||||
|
||||
+14
-8
@@ -130,7 +130,7 @@ in
|
||||
_create = diskoLib.mkCreateOption {
|
||||
inherit config options;
|
||||
default = ''
|
||||
if ! blkid "${config.device}" >/dev/null || ! (blkid "${config.device}" -o export | grep -q '^TYPE='); then
|
||||
if ! blkid "${config.device}" >/dev/null || ! cryptsetup isLuks "${config.device}"; then
|
||||
${lib.optionalString config.askPassword ''
|
||||
promptSecret() {
|
||||
prompt=$1
|
||||
@@ -147,7 +147,9 @@ in
|
||||
promptSecret "Enter password for ${config.device}: " password
|
||||
promptSecret "Enter password for ${config.device} again to be safe: " password_check
|
||||
export password
|
||||
[ "$password" = "$password_check" ]
|
||||
if [ "$password" != "$password_check" ]; then
|
||||
exit 1
|
||||
fi
|
||||
set -x
|
||||
else
|
||||
export password=disko
|
||||
@@ -158,13 +160,17 @@ in
|
||||
done
|
||||
''}
|
||||
cryptsetup -q luksFormat "${config.device}" ${toString config.extraFormatArgs} ${keyFileArgs}
|
||||
${cryptsetupOpen} --persistent
|
||||
${toString (
|
||||
lib.forEach config.additionalKeyFiles (keyFile: ''
|
||||
cryptsetup luksAddKey "${config.device}" ${keyFile} ${keyFileArgs}
|
||||
'')
|
||||
)}
|
||||
fi
|
||||
|
||||
if ! cryptsetup status "${config.name}" >/dev/null; then
|
||||
${cryptsetupOpen} --persistent
|
||||
fi
|
||||
${toString (
|
||||
lib.forEach config.additionalKeyFiles (keyFile: ''
|
||||
cryptsetup luksAddKey "${config.device}" ${keyFile} ${keyFileArgs}
|
||||
'')
|
||||
)}
|
||||
|
||||
${lib.optionalString (config.content != null) config.content._create}
|
||||
'';
|
||||
};
|
||||
|
||||
+14
-2
@@ -9,19 +9,30 @@
|
||||
binlore,
|
||||
diskoVersion,
|
||||
stdenv,
|
||||
xcp,
|
||||
}:
|
||||
|
||||
let
|
||||
self = stdenvNoCC.mkDerivation (finalAttrs: {
|
||||
name = "disko";
|
||||
src = ./.;
|
||||
src = lib.fileset.toSource {
|
||||
root = ./.;
|
||||
fileset = lib.fileset.unions [
|
||||
./disko
|
||||
./disko-install
|
||||
./install-cli.nix
|
||||
./cli.nix
|
||||
./default.nix
|
||||
./disk-deactivate
|
||||
./lib
|
||||
];
|
||||
};
|
||||
nativeBuildInputs = [
|
||||
makeWrapper
|
||||
];
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin $out/share/disko
|
||||
cp -r install-cli.nix cli.nix default.nix disk-deactivate lib $out/share/disko
|
||||
set -x
|
||||
|
||||
scripts=(disko)
|
||||
${lib.optionalString (!stdenv.isDarwin) ''
|
||||
@@ -39,6 +50,7 @@ let
|
||||
[
|
||||
nix
|
||||
coreutils
|
||||
xcp
|
||||
]
|
||||
++ lib.optional (!stdenv.isDarwin) nixos-install-tools
|
||||
)
|
||||
|
||||
@@ -45,7 +45,12 @@ fi
|
||||
nix-fast-build --no-link -j 2 --eval-workers 2 --flake .#checks
|
||||
|
||||
# Update the version file
|
||||
echo "{ version = \"$version\"; released = true; }" > version.nix
|
||||
cat > version.nix <<EOF
|
||||
{
|
||||
version = "$version";
|
||||
released = false;
|
||||
}
|
||||
EOF
|
||||
|
||||
# Commit and tag the release
|
||||
git commit -am "release: v$version"
|
||||
|
||||
+110
-29
@@ -7,39 +7,120 @@ diskoLib.testLib.makeDiskoTest {
|
||||
name = "bcachefs";
|
||||
disko-config = ../example/bcachefs.nix;
|
||||
enableOCR = true;
|
||||
bootCommands = ''
|
||||
machine.wait_for_text("enter passphrase for /");
|
||||
machine.send_chars("secretsecret\n");
|
||||
machine.wait_for_text("enter passphrase for /home");
|
||||
machine.send_chars("secretsecret\n");
|
||||
machine.wait_for_text("enter passphrase for /nix");
|
||||
machine.send_chars("secretsecret\n");
|
||||
'';
|
||||
extraSystemConfig = {
|
||||
environment.systemPackages = [
|
||||
pkgs.jq
|
||||
];
|
||||
};
|
||||
extraTestScript = ''
|
||||
machine.succeed("mountpoint /");
|
||||
# @todo Verify all devices are part of the filesystem.
|
||||
# @todo Check device labels and group assignments.
|
||||
# Verify mount options were applied.
|
||||
machine.succeed("mount | grep ' / ' | grep -q 'compression=lz4'");
|
||||
machine.succeed("mount | grep ' / ' | grep -q 'background_compression=lz4'");
|
||||
# @todo Verify mountpoint dependency order was respected.
|
||||
# @todo Add tests for subvolumes.
|
||||
# Print debug information.
|
||||
machine.succeed("ls -la /subvolumes >&2");
|
||||
machine.succeed("lsblk >&2");
|
||||
machine.succeed("lsblk -f >&2");
|
||||
machine.succeed("mount >&2");
|
||||
'';
|
||||
# extraSystemConfig = { pkgs, ... }: {
|
||||
# # @todo Do we need to add any attributes here?
|
||||
# boot = {
|
||||
# supportedFilesystems = [ "bcachefs" ];
|
||||
# initrd = {
|
||||
# supportedFilesystems = [ "bcachefs" ];
|
||||
# # systemd.enable = false;
|
||||
# };
|
||||
# };
|
||||
# environment.systemPackages = [
|
||||
# pkgs.bcachefs-tools
|
||||
# pkgs.util-linux
|
||||
# ];
|
||||
# };
|
||||
# extraInstallerConfig = {
|
||||
# # @todo Do we need to add any attributes here?
|
||||
# };
|
||||
bootCommands = ''
|
||||
machine.wait_for_text("enter passphrase for");
|
||||
machine.send_chars("secretsecret\n");
|
||||
machine.succeed("bcachefs show-super /dev/vda2 >&2");
|
||||
machine.succeed("bcachefs show-super /dev/vdd1 >&2");
|
||||
machine.succeed("findmnt --json >&2");
|
||||
|
||||
# Verify subvolume structure.
|
||||
machine.succeed("test -d /subvolumes/root");
|
||||
machine.succeed("test -d /subvolumes/home");
|
||||
machine.succeed("test -d /subvolumes/home/user");
|
||||
machine.succeed("test -d /subvolumes/nix");
|
||||
machine.succeed("test -d /subvolumes/test");
|
||||
machine.fail("test -d /subvolumes/non-existent");
|
||||
|
||||
# Verify existence of mountpoints.
|
||||
machine.succeed("mountpoint /");
|
||||
machine.succeed("mountpoint /home");
|
||||
machine.succeed("mountpoint /nix");
|
||||
machine.succeed("mountpoint /home/Documents");
|
||||
machine.fail("mountpoint /non-existent");
|
||||
|
||||
# Verify device membership and labels.
|
||||
machine.succeed("bcachefs show-super /dev/vda2 | grep 'Devices:' | grep -q '3'");
|
||||
machine.succeed("bcachefs show-super /dev/vdd1 | grep 'Devices:' | grep -q '1'");
|
||||
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]+Label:[[:space:]]+vdb2[[:space:]]\([[:digit:]]+\)'");
|
||||
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]+Label:[[:space:]]+vdc1[[:space:]]\([[:digit:]]+\)'");
|
||||
machine.succeed("bcachefs show-super /dev/vda2 | grep -qE '^[[:space:]]+Label:[[:space:]]+vdd1[[:space:]]\([[:digit:]]+\)'");
|
||||
machine.succeed("bcachefs show-super /dev/vdd1 | grep -qE '^[[:space:]]+Label:[[:space:]]+vde1[[:space:]]\([[:digit:]]+\)'");
|
||||
machine.fail("bcachefs show-super /dev/vda2 | grep 'Label:' | grep -q 'non-existent'");
|
||||
|
||||
# @todo Verify format arguments.
|
||||
|
||||
# Verify mount options from configuration.
|
||||
machine.succeed("""
|
||||
findmnt --json \
|
||||
| jq -e ' \
|
||||
.filesystems[] \
|
||||
| select(.target == "/") \
|
||||
| .options \
|
||||
| split(",") \
|
||||
| contains(["verbose", "compression=lz4", "background_compression=lz4"]) \
|
||||
'
|
||||
""");
|
||||
|
||||
machine.succeed("""
|
||||
findmnt --json \
|
||||
| jq -e ' \
|
||||
.filesystems[] \
|
||||
| .. \
|
||||
| select(.target? == "/home/Documents") \
|
||||
| .options \
|
||||
| split(",") \
|
||||
| contains(["verbose"]) \
|
||||
'
|
||||
""");
|
||||
|
||||
machine.fail("""
|
||||
findmnt --json \
|
||||
| jq -e ' \
|
||||
.filesystems[] \
|
||||
| select(.target == "/") \
|
||||
| .options \
|
||||
| split(",") \
|
||||
| contains(["non-existent"]) \
|
||||
'
|
||||
""");
|
||||
|
||||
# Verify device composition of filesystems.
|
||||
machine.succeed("""
|
||||
findmnt --json \
|
||||
| jq -e ' \
|
||||
.filesystems[] \
|
||||
| select(.target == "/") \
|
||||
| .source | split(":") \
|
||||
| contains(["/dev/vda2", "/dev/vdb1", "/dev/vdc1"]) \
|
||||
'
|
||||
""");
|
||||
|
||||
machine.succeed("""
|
||||
findmnt --json \
|
||||
| jq -e ' \
|
||||
.filesystems[] \
|
||||
| .. \
|
||||
| select(.target? == "/home/Documents") \
|
||||
| .source \
|
||||
| contains("/dev/disk/by-uuid/64e50034-ebe2-eaf8-1f93-cf56266a8d86") \
|
||||
'
|
||||
""");
|
||||
|
||||
machine.fail("""
|
||||
findmnt --json \
|
||||
| jq -e ' \
|
||||
.filesystems[] \
|
||||
| select(.target == "/") \
|
||||
| .source | split(":") \
|
||||
| contains(["/dev/non-existent"]) \
|
||||
'
|
||||
""");
|
||||
'';
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
version = "1.10.0";
|
||||
version = "1.12.0";
|
||||
released = false;
|
||||
}
|
||||
Reference in new issue
Block a user