mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 21:13:28 +01:00
Compare commits
131
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6eb3487673 | ||
|
|
2db1d64fc0 | ||
|
|
6c1b834456 | ||
|
|
8d6dd03a1c | ||
|
|
19c1140419 | ||
|
|
15dbf8cebd | ||
|
|
af4a580628 | ||
|
|
dc4687a53d | ||
|
|
be1e4321c9 | ||
|
|
fa5746ecea | ||
|
|
eb0e21b33b | ||
|
|
7dcd5cda34 | ||
|
|
ff2d853a84 | ||
|
|
c23ac2891c | ||
|
|
5d6c85c1d0 | ||
|
|
d478e2f9f3 | ||
|
|
4edb87a2ac | ||
|
|
a825e29a3b | ||
|
|
bf440582c4 | ||
|
|
54be8abff0 | ||
|
|
e51159153b | ||
|
|
6438340415 | ||
|
|
85942f35d3 | ||
|
|
40da43e8e5 | ||
|
|
4b841b9c3a | ||
|
|
fa88901f1e | ||
|
|
9503f225a4 | ||
|
|
26ade10051 | ||
|
|
ff3568858c | ||
|
|
68ef26bb78 | ||
|
|
18d0a984cc | ||
|
|
bf0abfde48 | ||
|
|
c53bfaa13a | ||
|
|
1ae7c794d9 | ||
|
|
f720e64ec3 | ||
|
|
f275b06323 | ||
|
|
33827d2bd1 | ||
|
|
79a12e659b | ||
|
|
ade21e2c96 | ||
|
|
cb6297aceb | ||
|
|
fe89f379e7 | ||
|
|
b1a94497b1 | ||
|
|
b64dddf61b | ||
|
|
4d5d07d37f | ||
|
|
11e3073dff | ||
|
|
b9ca21dc6c | ||
|
|
b8aecf159f | ||
|
|
49f8aa791f | ||
|
|
5be012e917 | ||
|
|
76816af65d | ||
|
|
c315045f42 | ||
|
|
84a5b93637 | ||
|
|
7d9940a4df | ||
|
|
3a4de9fa3a | ||
|
|
7ea6edd857 | ||
|
|
2ee76c861a | ||
|
|
d8f3cfc582 | ||
|
|
60375cf096 | ||
|
|
600d2e1d2f | ||
|
|
194a9965d1 | ||
|
|
a08bfe06b3 | ||
|
|
dcd15a37f7 | ||
|
|
d3e3aa7a14 | ||
|
|
d32f2d1750 | ||
|
|
65a441502c | ||
|
|
2097ca7a9e | ||
|
|
a0c967fef4 | ||
|
|
825605c2c7 | ||
|
|
0f31ad735e | ||
|
|
9c74188ec6 | ||
|
|
22cd4b7e49 | ||
|
|
98894c8598 | ||
|
|
785c1e02c7 | ||
|
|
67a130b984 | ||
|
|
2814a5224a | ||
|
|
3faa300212 | ||
|
|
b71e3faca9 | ||
|
|
5655a13ac9 | ||
|
|
a75ba3b87b | ||
|
|
aa006252c8 | ||
|
|
341482e2f4 | ||
|
|
ff6e596353 | ||
|
|
869ba3a874 | ||
|
|
255e11e831 | ||
|
|
2ed5e30fc7 | ||
|
|
f35ae6300f | ||
|
|
3e83c11038 | ||
|
|
8d80e4e8fc | ||
|
|
47bc8dfb6f | ||
|
|
0433c7e883 | ||
|
|
abc8baff33 | ||
|
|
84dd8eea9a | ||
|
|
fd3e326e9a | ||
|
|
3a8a8713bf | ||
|
|
97c0c4d707 | ||
|
|
eb1bb9fe27 | ||
|
|
4cbd22d868 | ||
|
|
0e5eb607f0 | ||
|
|
a0c384e0a3 | ||
|
|
811fb748fd | ||
|
|
c3b83db725 | ||
|
|
feeb365e31 | ||
|
|
b1aa08f8ce | ||
|
|
da52cf4020 | ||
|
|
92ad678418 | ||
|
|
caad548415 | ||
|
|
639d1520df | ||
|
|
d192ffd944 | ||
|
|
6a472cc248 | ||
|
|
9b56c1afdb | ||
|
|
cb64993826 | ||
|
|
eaa51560df | ||
|
|
9f97bd0995 | ||
|
|
5fd852c415 | ||
|
|
9c7de5582e | ||
|
|
486250f404 | ||
|
|
7d4cbcd235 | ||
|
|
5e40e02978 | ||
|
|
6bfa3a18d4 | ||
|
|
21b2de0a20 | ||
|
|
a8bdb16b47 | ||
|
|
051ff61420 | ||
|
|
dd3d2a5e93 | ||
|
|
60d4914b98 | ||
|
|
f3f8254fcc | ||
|
|
3fc91a7576 | ||
|
|
94bc0f5bb0 | ||
|
|
daca7be309 | ||
|
|
856a290215 | ||
|
|
380847d94f | ||
|
|
3979285062 |
No files matched your search
@@ -0,0 +1,35 @@
|
||||
# This file contains a list of commits that are not likely what you
|
||||
# are looking for in a blame, such as mass reformatting or renaming.
|
||||
#
|
||||
# If a commit's line ends with `# !autorebase <command>`,
|
||||
# where <command> is an idempotent bash command that reapplies the changes from the commit,
|
||||
# the `https://github.com/NixOS/nixpkgs/blob/master/maintainers/scripts/auto-rebase/run.sh` script can be used to rebase
|
||||
# across that commit while automatically resolving merge conflicts caused by the commit.
|
||||
#
|
||||
# You can set this file as a default ignore file for blame by running
|
||||
# the following command.
|
||||
#
|
||||
# $ git config blame.ignoreRevsFile .git-blame-ignore-revs
|
||||
#
|
||||
# To temporarily not use this file add
|
||||
# --ignore-revs-file=""
|
||||
# to your blame command.
|
||||
#
|
||||
# The ignoreRevsFile can't be set globally due to blame failing if the file isn't present.
|
||||
# To not have to set the option in every repository it is needed in,
|
||||
# save the following script in your path with the name "git-bblame"
|
||||
# now you can run
|
||||
# $ git bblame $FILE
|
||||
# to use the .git-blame-ignore-revs file if it is present.
|
||||
#
|
||||
# #!/usr/bin/env bash
|
||||
# repo_root=$(git rev-parse --show-toplevel)
|
||||
# if [[ -e $repo_root/.git-blame-ignore-revs ]]; then
|
||||
# git blame --ignore-revs-file="$repo_root/.git-blame-ignore-revs" $@
|
||||
# else
|
||||
# git blame $@
|
||||
# fi
|
||||
|
||||
|
||||
# treewide: format all files
|
||||
bd9da344ab53d297bd3e2baab0805b2e51b31136
|
||||
@@ -13,7 +13,7 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Install Nix
|
||||
uses: cachix/install-nix-action@v30
|
||||
uses: cachix/install-nix-action@v31
|
||||
- name: Update flake.lock
|
||||
uses: DeterminateSystems/update-flake-lock@v24
|
||||
with:
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
result
|
||||
result-*
|
||||
.direnv/
|
||||
|
||||
# Created by the NixOS interactive test driver
|
||||
.nixos-test-history
|
||||
@@ -76,6 +76,7 @@ A simple disko configuration may look like this:
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [ "umask=0077" ];
|
||||
};
|
||||
};
|
||||
root = {
|
||||
@@ -99,7 +100,7 @@ a disk named /dev/sda, you would run the following command to partition, format
|
||||
and mount the disk.
|
||||
|
||||
```console
|
||||
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko/latest -- --mode disko /tmp/disk-config.nix
|
||||
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko/latest -- --mode destroy,format,mount /tmp/disk-config.nix
|
||||
```
|
||||
|
||||
## Related Tools
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, lib ? pkgs.lib
|
||||
, mode ? "mount"
|
||||
, flake ? null
|
||||
, flakeAttr ? null
|
||||
, diskoFile ? null
|
||||
, rootMountPoint ? "/mnt"
|
||||
, noDeps ? false
|
||||
, ...
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
lib ? pkgs.lib,
|
||||
mode ? "mount",
|
||||
flake ? null,
|
||||
flakeAttr ? null,
|
||||
diskoFile ? null,
|
||||
rootMountPoint ? "/mnt",
|
||||
noDeps ? false,
|
||||
...
|
||||
}@args:
|
||||
let
|
||||
disko = import ./. {
|
||||
@@ -14,55 +15,107 @@ let
|
||||
inherit lib;
|
||||
};
|
||||
|
||||
diskoAttr =
|
||||
if noDeps then
|
||||
{
|
||||
format = "formatScriptNoDeps";
|
||||
mount = "mountScriptNoDeps";
|
||||
disko = "diskoScriptNoDeps";
|
||||
hasDiskoFile = diskoFile != null;
|
||||
|
||||
# legacy aliases
|
||||
create = "createScriptNoDeps";
|
||||
zap_create_mount = "diskoScriptNoDeps";
|
||||
}.${mode}
|
||||
diskoAttr =
|
||||
(
|
||||
if noDeps then
|
||||
(
|
||||
if hasDiskoFile then
|
||||
{
|
||||
destroy = "_cliDestroyNoDeps";
|
||||
format = "_cliFormatNoDeps";
|
||||
mount = "_cliMountNoDeps";
|
||||
unmount = "_cliUnmountNoDeps";
|
||||
|
||||
"format,mount" = "_cliFormatMountNoDeps";
|
||||
"destroy,format,mount" = "_cliDestroyFormatMountNoDeps";
|
||||
}
|
||||
else
|
||||
{
|
||||
format = "formatScript";
|
||||
mount = "mountScript";
|
||||
disko = "diskoScript";
|
||||
destroy = "destroyNoDeps";
|
||||
format = "formatNoDeps";
|
||||
mount = "mountNoDeps";
|
||||
unmount = "unmountNoDeps";
|
||||
|
||||
"format,mount" = "formatMountNoDeps";
|
||||
"destroy,format,mount" = "destroyFormatMountNoDeps";
|
||||
}
|
||||
)
|
||||
// {
|
||||
# legacy aliases
|
||||
disko = "diskoScriptNoDeps";
|
||||
create = "createScriptNoDeps";
|
||||
zap_create_mount = "diskoScriptNoDeps";
|
||||
}
|
||||
else
|
||||
(
|
||||
if hasDiskoFile then
|
||||
{
|
||||
destroy = "_cliDestroy";
|
||||
format = "_cliFormat";
|
||||
mount = "_cliMount";
|
||||
unmount = "_cliUnmount";
|
||||
|
||||
"format,mount" = "_cliFormatMount";
|
||||
"destroy,format,mount" = "_cliDestroyFormatMount";
|
||||
}
|
||||
else
|
||||
{
|
||||
destroy = "destroy";
|
||||
format = "format";
|
||||
mount = "mount";
|
||||
unmount = "unmount";
|
||||
|
||||
"format,mount" = "formatMount";
|
||||
"destroy,format,mount" = "destroyFormatMount";
|
||||
}
|
||||
)
|
||||
// {
|
||||
# legacy aliases
|
||||
disko = "diskoScript";
|
||||
create = "createScript";
|
||||
zap_create_mount = "diskoScript";
|
||||
}.${mode};
|
||||
}
|
||||
).${mode};
|
||||
|
||||
hasDiskoConfigFlake =
|
||||
diskoFile != null || lib.hasAttrByPath [ "diskoConfigurations" flakeAttr ] (builtins.getFlake flake);
|
||||
hasDiskoFile || lib.hasAttrByPath [ "diskoConfigurations" flakeAttr ] (builtins.getFlake flake);
|
||||
|
||||
hasDiskoModuleFlake =
|
||||
lib.hasAttrByPath [ "nixosConfigurations" flakeAttr "config" "disko" "devices" ] (builtins.getFlake flake);
|
||||
hasDiskoModuleFlake = lib.hasAttrByPath [
|
||||
"nixosConfigurations"
|
||||
flakeAttr
|
||||
"config"
|
||||
"disko"
|
||||
"devices"
|
||||
] (builtins.getFlake flake);
|
||||
|
||||
diskFormat =
|
||||
let
|
||||
diskoConfig =
|
||||
if diskoFile != null then
|
||||
if hasDiskoFile then
|
||||
import diskoFile
|
||||
else
|
||||
(builtins.getFlake flake).diskoConfigurations.${flakeAttr};
|
||||
in
|
||||
if builtins.isFunction diskoConfig then
|
||||
diskoConfig ({ inherit lib; } // args)
|
||||
else
|
||||
diskoConfig;
|
||||
if builtins.isFunction diskoConfig then diskoConfig ({ inherit lib; } // args) else diskoConfig;
|
||||
|
||||
diskoEval =
|
||||
disko.${diskoAttr} diskFormat pkgs;
|
||||
diskoEval = disko.${diskoAttr} diskFormat pkgs;
|
||||
|
||||
diskoScript =
|
||||
if hasDiskoConfigFlake then
|
||||
diskoEval
|
||||
else if (lib.traceValSeq hasDiskoModuleFlake) then
|
||||
else if hasDiskoModuleFlake then
|
||||
(builtins.getFlake flake).nixosConfigurations.${flakeAttr}.config.system.build.${diskoAttr}
|
||||
or (pkgs.writeShellScriptBin "disko-compat-error" ''
|
||||
echo 'Error: Attribute `nixosConfigurations.${flakeAttr}.config.system.build.${diskoAttr}` >&2
|
||||
echo ' not found in flake `${flake}`!' >&2
|
||||
echo ' This is probably caused by the locked version of disko in the flake' >&2
|
||||
echo ' being different from the version of disko you executed.' >&2
|
||||
echo 'EITHER set the `disko` input of your flake to `github:nix-community/disko/latest`,' >&2
|
||||
echo ' run `nix flake update disko` in the flake directory and then try again,' >&2
|
||||
echo 'OR run `nix run github:nix-community/disko/v1.9.0 -- --help` and use one of its modes.' >&2
|
||||
exit 1;'')
|
||||
else
|
||||
(builtins.abort "couldn't find `diskoConfigurations.${flakeAttr}` or `nixosConfigurations.${flakeAttr}.config.disko.devices`");
|
||||
|
||||
|
||||
+84
-20
@@ -1,10 +1,13 @@
|
||||
{ lib ? import <nixpkgs/lib>
|
||||
, rootMountPoint ? "/mnt"
|
||||
, checked ? false
|
||||
, diskoLib ? import ./lib { inherit lib rootMountPoint; }
|
||||
{
|
||||
lib ? import <nixpkgs/lib>,
|
||||
rootMountPoint ? "/mnt",
|
||||
checked ? false,
|
||||
diskoLib ? import ./lib { inherit lib rootMountPoint; },
|
||||
}:
|
||||
let
|
||||
eval = cfg: lib.evalModules {
|
||||
eval =
|
||||
cfg:
|
||||
lib.evalModules {
|
||||
modules = lib.singleton {
|
||||
# _file = toString input;
|
||||
imports = lib.singleton { disko.devices = cfg.disko.devices; };
|
||||
@@ -15,29 +18,90 @@ let
|
||||
};
|
||||
};
|
||||
};
|
||||
# We might instead reuse some of the deprecated output names to refer to the values the _cli* outputs currently do,
|
||||
# but this warning allows us to get feedback from users early in case they have a use case we haven't considered.
|
||||
warnDeprecated =
|
||||
name:
|
||||
lib.warn "the ${name} output is deprecated and will be removed, please open an issue if you're using it!";
|
||||
in
|
||||
{
|
||||
lib = lib.warn "the .lib.lib output is deprecated" diskoLib;
|
||||
lib = warnDeprecated ".lib.lib" diskoLib;
|
||||
|
||||
# legacy alias
|
||||
create = cfg: builtins.trace "the create output is deprecated, use format instead" (eval cfg).config.disko.devices._create;
|
||||
createScript = cfg: pkgs: builtins.trace "the create output is deprecated, use format instead" ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).formatScript;
|
||||
createScriptNoDeps = cfg: pkgs: builtins.trace "the create output is deprecated, use format instead" ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).formatScriptNoDeps;
|
||||
_cliDestroy =
|
||||
cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).destroy;
|
||||
_cliDestroyNoDeps =
|
||||
cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).destroyNoDeps;
|
||||
|
||||
format = cfg: (eval cfg).config.disko.devices._create;
|
||||
formatScript = cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).formatScript;
|
||||
formatScriptNoDeps = cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).formatScriptNoDeps;
|
||||
_cliFormat = cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).format;
|
||||
_cliFormatNoDeps =
|
||||
cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).formatNoDeps;
|
||||
|
||||
mount = cfg: (eval cfg).config.disko.devices._mount;
|
||||
mountScript = cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).mountScript;
|
||||
mountScriptNoDeps = cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).mountScriptNoDeps;
|
||||
_cliMount = cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).mount;
|
||||
_cliMountNoDeps =
|
||||
cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).mountNoDeps;
|
||||
|
||||
disko = cfg: (eval cfg).config.disko.devices._disko;
|
||||
diskoScript = cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).diskoScript;
|
||||
diskoScriptNoDeps = cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).diskoScriptNoDeps;
|
||||
_cliUnmount =
|
||||
cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).unmount;
|
||||
_cliUnmountNoDeps =
|
||||
cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).unmountNoDeps;
|
||||
|
||||
_cliFormatMount =
|
||||
cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).formatMount;
|
||||
_cliFormatMountNoDeps =
|
||||
cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).formatMountNoDeps;
|
||||
|
||||
_cliDestroyFormatMount =
|
||||
cfg: pkgs: ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).destroyFormatMount;
|
||||
_cliDestroyFormatMountNoDeps =
|
||||
cfg: pkgs:
|
||||
((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).destroyFormatMountNoDeps;
|
||||
|
||||
# legacy aliases
|
||||
create = cfg: warnDeprecated "create" (eval cfg).config.disko.devices._create;
|
||||
createScript =
|
||||
cfg: pkgs:
|
||||
warnDeprecated "createScript"
|
||||
((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).formatScript;
|
||||
createScriptNoDeps =
|
||||
cfg: pkgs:
|
||||
warnDeprecated "createScriptNoDeps"
|
||||
((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).formatScriptNoDeps;
|
||||
|
||||
format = cfg: warnDeprecated "format" (eval cfg).config.disko.devices._create;
|
||||
formatScript =
|
||||
cfg: pkgs:
|
||||
warnDeprecated "formatScript"
|
||||
((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).formatScript;
|
||||
formatScriptNoDeps =
|
||||
cfg: pkgs:
|
||||
warnDeprecated "formatScriptNoDeps"
|
||||
((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).formatScriptNoDeps;
|
||||
|
||||
mount = cfg: warnDeprecated "mount" (eval cfg).config.disko.devices._mount;
|
||||
mountScript =
|
||||
cfg: pkgs:
|
||||
warnDeprecated "mountScript"
|
||||
((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).mountScript;
|
||||
mountScriptNoDeps =
|
||||
cfg: pkgs:
|
||||
warnDeprecated "mountScriptNoDeps"
|
||||
((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).mountScriptNoDeps;
|
||||
|
||||
disko = cfg: warnDeprecated "disko" (eval cfg).config.disko.devices._disko;
|
||||
diskoScript =
|
||||
cfg: pkgs:
|
||||
warnDeprecated "diskoScript"
|
||||
((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).diskoScript;
|
||||
diskoScriptNoDeps =
|
||||
cfg: pkgs:
|
||||
warnDeprecated "diskoScriptNoDeps"
|
||||
((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).diskoScriptNoDeps;
|
||||
|
||||
# we keep this old output for backwards compatibility
|
||||
diskoNoDeps = cfg: pkgs: builtins.trace "the diskoNoDeps output is deprecated, please use disko instead" ((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).diskoScriptNoDeps;
|
||||
diskoNoDeps =
|
||||
cfg: pkgs:
|
||||
warnDeprecated "diskoNoDeps"
|
||||
((eval cfg).config.disko.devices._scripts { inherit pkgs checked; }).diskoScriptNoDeps;
|
||||
|
||||
config = cfg: (eval cfg).config.disko.devices._config;
|
||||
packages = cfg: (eval cfg).config.disko.devices._packages;
|
||||
|
||||
@@ -43,6 +43,10 @@ def deactivate:
|
||||
"cryptsetup luksClose \(.path)",
|
||||
"wipefs --all -f \(.path)"
|
||||
]
|
||||
elif .type == "swap" then
|
||||
[
|
||||
"swapoff \(.path)",
|
||||
]
|
||||
elif .type == "lvm" then
|
||||
(.name | split("-")[0]) as $vgname |
|
||||
(.name | split("-")[1]) as $lvname |
|
||||
|
||||
@@ -9,6 +9,7 @@ declare disko_config
|
||||
# mount was chosen as the default mode because it's less destructive
|
||||
mode=mount
|
||||
nix_args=()
|
||||
skip_destroy_safety_check=false
|
||||
|
||||
# DISKO_VERSION is set by the wrapper in package.nix
|
||||
DISKO_VERSION="${DISKO_VERSION:="unknown! This is a bug, please report it!"}"
|
||||
@@ -25,10 +26,12 @@ or else from the disko module of a NixOS configuration of that name under .nixos
|
||||
Options:
|
||||
|
||||
* -m, --mode mode
|
||||
set the mode, either format, mount or disko
|
||||
format: create partition tables, zpools, lvms, raids and filesystems
|
||||
mount: mount the partition at the specified root-mountpoint
|
||||
disko: first unmount and destroy all filesystems on the disks we want to format, then run the create and mount mode
|
||||
set the mode, either destroy, format, mount, unmount, format,mount or destroy,format,mount
|
||||
destroy: unmount filesystems and destroy partition tables of the selected disks
|
||||
format: create partition tables, zpools, lvms, raids and filesystems if they don't exist yet
|
||||
mount: mount the partitions at the specified root-mountpoint
|
||||
format,mount: run format and mount in sequence
|
||||
destroy,format,mount: run all three modes in sequence. Previously known as --mode disko
|
||||
* -f, --flake uri
|
||||
fetch the disko config relative to this flake's root
|
||||
* --arg name value
|
||||
@@ -42,6 +45,8 @@ Options:
|
||||
* --no-deps
|
||||
avoid adding another dependency closure to an in-memory installer
|
||||
requires all necessary dependencies to be available in the environment
|
||||
* --yes-wipe-all-disks
|
||||
skip the safety check for destroying partitions, useful for automation
|
||||
* --debug
|
||||
run with set -x
|
||||
* --help
|
||||
@@ -93,6 +98,9 @@ while [[ $# -gt 0 ]]; do
|
||||
--no-deps)
|
||||
nix_args+=(--arg noDeps true)
|
||||
;;
|
||||
--yes-wipe-all-disks)
|
||||
skip_destroy_safety_check=true
|
||||
;;
|
||||
--show-trace)
|
||||
nix_args+=("$1")
|
||||
;;
|
||||
@@ -126,8 +134,16 @@ nixBuild() {
|
||||
fi
|
||||
}
|
||||
|
||||
if ! { [[ $mode = "format" ]] || [[ $mode = "mount" ]] || [[ $mode = "disko" ]] || [[ $mode = "create" ]] || [[ $mode = "zap_create_mount" ]] ; }; then
|
||||
abort "mode must be either format, mount or disko"
|
||||
if ! {
|
||||
# Base modes
|
||||
[[ $mode = "destroy" ]] || [[ $mode = "format" ]] || [[ $mode = "mount" ]] || [[ $mode = "unmount" ]] ||
|
||||
# Combined modes
|
||||
[[ $mode = "format,mount" ]] ||
|
||||
[[ $mode = "destroy,format,mount" ]] || # Replaces --mode disko
|
||||
# Legacy modes, will be removed in next major version
|
||||
[[ $mode = "disko" ]] || [[ $mode = "create" ]] || [[ $mode = "zap_create_mount" ]] ;
|
||||
}; then
|
||||
abort 'mode must be one of "destroy", "format", "mount", "destroy,format,mount" or "format,mount"'
|
||||
fi
|
||||
|
||||
if [[ -n "${flake+x}" ]]; then
|
||||
@@ -159,8 +175,19 @@ script=$(nixBuild "${libexec_dir}"/cli.nix \
|
||||
--argstr mode "$mode" \
|
||||
"${nix_args[@]}"
|
||||
)
|
||||
|
||||
command=("$(echo "$script"/bin/*)")
|
||||
if [[ $mode = "destroy,format,mount" && $skip_destroy_safety_check = true ]]; then
|
||||
command+=("--yes-wipe-all-disks")
|
||||
fi
|
||||
|
||||
# Legacy modes don't support --yes-wipe-all-disks and are not in `$script/bin`
|
||||
if [[ $mode = "disko" ]] || [[ $mode = "create" ]] || [[ $mode = "zap_create_mount" ]] ; then
|
||||
command=("$script")
|
||||
fi
|
||||
|
||||
if [[ -n "${dry_run+x}" ]]; then
|
||||
echo "$script"
|
||||
echo "${command[@]}"
|
||||
else
|
||||
exec "$script"
|
||||
exec "${command[@]}"
|
||||
fi
|
||||
+29
-9
@@ -20,6 +20,8 @@ Usage: $0 [OPTIONS]
|
||||
Specify this option if you plan to boot from this disk on the current machine,
|
||||
but not if you plan to move the disk to another machine.
|
||||
--system-config JSON Merges the specified JSON object into the NixOS configuration.
|
||||
--mount-point PATH Specify the mount point for the NixOS installation.
|
||||
Default: /mnt/disko-install-root
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -46,6 +48,7 @@ dry_run=
|
||||
extraSystemConfig="{}"
|
||||
diskoAttr=diskoScript
|
||||
writeEfiBootEntries=false
|
||||
mountPoint=/mnt/disko-install-root
|
||||
declare -A diskMappings
|
||||
declare -A extraFiles
|
||||
|
||||
@@ -135,6 +138,14 @@ parseArgs() {
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
--mount-point)
|
||||
if [[ $# -lt 2 ]]; then
|
||||
echo "Option $1 requires an argument" >&2
|
||||
exit 1
|
||||
fi
|
||||
mountPoint=$2
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1" >&2
|
||||
showUsage
|
||||
@@ -146,7 +157,6 @@ parseArgs() {
|
||||
}
|
||||
|
||||
cleanupMountPoint() {
|
||||
mountPoint=$1
|
||||
if mountpoint -q "${mountPoint}"; then
|
||||
umount -R "${mountPoint}"
|
||||
fi
|
||||
@@ -161,6 +171,14 @@ nixBuild() {
|
||||
fi
|
||||
}
|
||||
|
||||
maybeRun () {
|
||||
if [[ -z ${dry_run-} ]]; then
|
||||
"$@"
|
||||
else
|
||||
echo "Would run: $*"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
parseArgs "$@"
|
||||
|
||||
@@ -170,7 +188,7 @@ main() {
|
||||
fi
|
||||
|
||||
# check if we are root
|
||||
if [[ "$EUID" -ne 0 ]]; then
|
||||
if [[ "$EUID" -ne 0 ]] && [[ -z ${dry_run-} ]]; then
|
||||
echo "This script must be run as root" >&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -190,12 +208,12 @@ main() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mountPoint="/mnt/disko-install-root"
|
||||
mkdir -p "${mountPoint}"
|
||||
chmod 755 "${mountPoint}" # bcachefs wants 755
|
||||
escapeMountPoint=$(printf '%q' "$mountPoint")
|
||||
maybeRun mkdir -p "${mountPoint}"
|
||||
maybeRun chmod 755 "${mountPoint}" # bcachefs wants 755
|
||||
# shellcheck disable=SC2064
|
||||
trap "cleanupMountPoint ${escapeMountPoint}" EXIT
|
||||
if [[ -z ${dry_run-} ]]; then
|
||||
trap cleanupMountPoint EXIT
|
||||
fi
|
||||
|
||||
outputs=$(nixBuild "${libexec_dir}"/install-cli.nix \
|
||||
"${nix_args[@]}" \
|
||||
@@ -222,7 +240,9 @@ main() {
|
||||
exit 0
|
||||
fi
|
||||
|
||||
"$disko_script"
|
||||
# We don't want swap as can break your running system in weird ways if you eject the disk
|
||||
# Hopefully disko-install has enough RAM to run without swap, otherwise we can make this configurable in future.
|
||||
DISKO_SKIP_SWAP=1 "$disko_script"
|
||||
|
||||
for source in "${!extraFiles[@]}"; do
|
||||
destination=${extraFiles[$source]}
|
||||
@@ -233,7 +253,7 @@ main() {
|
||||
# nix copy uses up a lot of memory and we work around issues with incorrect checksums in our store
|
||||
# that can be caused by using closureInfo in combination with multiple builders and non-deterministic builds.
|
||||
# Therefore if we have a blank store, we copy the store paths and registration from the closureInfo.
|
||||
if [[ ! -d "${mountPoint}/nix/store" ]]; then
|
||||
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"
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
{ lib, nixosOptionsDoc, runCommand, fetchurl, pandoc }:
|
||||
{
|
||||
lib,
|
||||
nixosOptionsDoc,
|
||||
runCommand,
|
||||
fetchurl,
|
||||
pandoc,
|
||||
}:
|
||||
|
||||
let
|
||||
diskoLib = import ./lib {
|
||||
@@ -21,13 +27,15 @@ let
|
||||
options = nixosOptionsDoc {
|
||||
options = eval.options;
|
||||
};
|
||||
md = (runCommand "disko-options.md" { } ''
|
||||
md =
|
||||
(runCommand "disko-options.md" { } ''
|
||||
cat >$out <<EOF
|
||||
# Disko options
|
||||
|
||||
EOF
|
||||
cat ${options.optionsCommonMark} >>$out
|
||||
'').overrideAttrs (_o: {
|
||||
'').overrideAttrs
|
||||
(_o: {
|
||||
# Work around https://github.com/hercules-ci/hercules-ci-agent/issues/168
|
||||
allowSubstitutes = true;
|
||||
});
|
||||
|
||||
+22
-5
@@ -92,7 +92,7 @@ In the this example we create a flake containing a nixos configuration for
|
||||
|
||||
- For custom image name output, define the image name in your Disko configuration:
|
||||
|
||||
```console
|
||||
```nix
|
||||
disko.devices.disk.<drive>.imageName = "nixos-x86_64-linux-generic-btrfs"; # Set your preferred name
|
||||
```
|
||||
|
||||
@@ -100,13 +100,30 @@ In the this example we create a flake containing a nixos configuration for
|
||||
|
||||
- For virtual drive use, define the image size in your Disko configuration:
|
||||
|
||||
```console
|
||||
```nix
|
||||
disko.devices.disk.<drive>.imageSize = "32G"; # Set your preferred size
|
||||
```
|
||||
|
||||
- If the `.raw` image size is not optimal, use `--write-to-disk` to write
|
||||
directly to a drive. This bypasses the `.raw` file generation, which saves on
|
||||
read/write operations and is suitable for single disk setups.
|
||||
- To build an image for another target platform, enable binfmt emulation support.
|
||||
|
||||
```nix
|
||||
disko.imageBuilder.enableBinfmt = true;
|
||||
```
|
||||
|
||||
This requires a working binfmt setup for your target platform on your build machine. Setup instructions are available for [NixOS](https://wiki.nixos.org/wiki/NixOS_on_ARM/Building_Images#Compiling_through_binfmt_QEMU) and other distros ([Arch Linux](https://wiki.archlinux.org/title/QEMU#Chrooting_into_arm/arm64_environment_from_x86_64), [Debian](https://wiki.debian.org/QemuUserEmulation)).
|
||||
|
||||
The relevant configuration for building `aarch64-linux` images on a `x86_64-linux` host looks like this:
|
||||
|
||||
```nix
|
||||
disko = {
|
||||
imageBuilder = {
|
||||
enableBinfmt = true;
|
||||
pkgs = inputs.nixpkgs.legacyPackages.x86_64-linux;
|
||||
kernelPackages = inputs.nixpkgs.legacyPackages.x86_64-linux.linuxPackages_latest;
|
||||
};
|
||||
|
||||
nixpkgs.hostPlatform = "aarch64-linux";
|
||||
```
|
||||
|
||||
## Understanding the Image Generation Process
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ For a fresh installation, where **disko-install** will handle partitioning and
|
||||
setting up the disk, use the following syntax:
|
||||
|
||||
```console
|
||||
sudo nix run 'github:nix-community/disko#disko-install/latest' -- --flake <flake-url>#<flake-attr> --disk <disk-name> <disk-device>
|
||||
sudo nix run 'github:nix-community/disko/latest#disko-install' -- --flake <flake-url>#<flake-attr> --disk <disk-name> <disk-device>
|
||||
```
|
||||
|
||||
Example:
|
||||
@@ -204,6 +204,11 @@ let
|
||||
self.nixosConfigurations.your-machine.config.system.build.diskoScript
|
||||
self.nixosConfigurations.your-machine.config.system.build.diskoScript.drvPath
|
||||
self.nixosConfigurations.your-machine.pkgs.stdenv.drvPath
|
||||
|
||||
# https://github.com/NixOS/nixpkgs/blob/f2fd33a198a58c4f3d53213f01432e4d88474956/nixos/modules/system/activation/top-level.nix#L342
|
||||
self.nixosConfigurations.your-machine.pkgs.perlPackages.ConfigIniFiles
|
||||
self.nixosConfigurations.your-machine.pkgs.perlPackages.FileSlurp
|
||||
|
||||
(self.nixosConfigurations.your-machine.pkgs.closureInfo { rootPaths = [ ]; }).drvPath
|
||||
] ++ builtins.map (i: i.outPath) (builtins.attrValues self.inputs);
|
||||
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
# disko - Declarative disk partitioning
|
||||
|
||||
<img src="./logo.jpeg" title="" alt="Project logo" width="247">
|
||||
<img src="./logo.png" title="" alt="Project logo" width="247">
|
||||
|
||||
[Documentation Index](./INDEX.md)
|
||||
|
||||
@@ -129,7 +129,7 @@ The following step will partition and format your disk, and mount it to `/mnt`.
|
||||
**Please note: This will erase any existing data on your disk.**
|
||||
|
||||
```console
|
||||
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko/latest -- --mode disko /tmp/disk-config.nix
|
||||
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko/latest -- --mode destroy,format,mount /tmp/disk-config.nix
|
||||
```
|
||||
|
||||
After the command has run, your file system should have been formatted and
|
||||
@@ -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
|
||||
existing lines that configure `systemd-boot`. The entries will look like this:
|
||||
|
||||
**Note:** Its not necessary to set `boot.loader.grub.device` here, since Disko
|
||||
**Note:** It's not necessary to set `boot.loader.grub.device` here, since Disko
|
||||
will take care of that automatically.
|
||||
|
||||
```nix
|
||||
|
||||
+8
-4
@@ -21,10 +21,12 @@ or else from the disko module of a NixOS configuration of that name under .nixos
|
||||
Options:
|
||||
|
||||
* -m, --mode mode
|
||||
set the mode, either format, mount or disko
|
||||
format: create partition tables, zpools, lvms, raids and filesystems
|
||||
mount: mount the partition at the specified root-mountpoint
|
||||
disko: first unmount and destroy all filesystems on the disks we want to format, then run the create and mount mode
|
||||
set the mode, either destroy, format, mount, format,mount or destroy,format,mount
|
||||
destroy: unmount filesystems and destroy partition tables of the selected disks
|
||||
format: create partition tables, zpools, lvms, raids and filesystems if they don't exist yet
|
||||
mount: mount the partitions at the specified root-mountpoint
|
||||
format,mount: run format and mount in sequence
|
||||
destroy,format,mount: run all three modes in sequence. Previously known as --mode disko
|
||||
* -f, --flake uri
|
||||
fetch the disko config relative to this flake's root
|
||||
* --arg name value
|
||||
@@ -40,4 +42,6 @@ Options:
|
||||
requires all necessary dependencies to be available in the environment
|
||||
* --debug
|
||||
run with set -x
|
||||
* --yes-wipe-all-disks
|
||||
skip the safety check for destroying partitions, useful for automation
|
||||
```
|
||||
@@ -42,6 +42,7 @@ for example like this:
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [ "umask=0077" ];
|
||||
};
|
||||
}
|
||||
{
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ nix build .#checks.x86_64-linux.simple-efi.driverInteractive
|
||||
result/bin/nixos-test-driver --keep-vm-state
|
||||
```
|
||||
|
||||
This will open an IPython prompt in which you can use th same objects and
|
||||
This will open an IPython prompt in which you can use the same objects and
|
||||
functions as in `extraTestScript`. In there, you can run
|
||||
|
||||
```
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [ "umask=0077" ];
|
||||
};
|
||||
};
|
||||
raid1 = {
|
||||
|
||||
@@ -26,7 +26,10 @@
|
||||
type = "btrfs";
|
||||
extraArgs = [ "-f" ]; # Override existing partition
|
||||
mountpoint = "/";
|
||||
mountOptions = [ "compress=zstd" "noatime" ];
|
||||
mountOptions = [
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
@@ -35,4 +38,3 @@
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -41,7 +41,10 @@
|
||||
"/home/user" = { };
|
||||
# Parent is not mounted so the mountpoint must be set
|
||||
"/nix" = {
|
||||
mountOptions = [ "compress=zstd" "noatime" ];
|
||||
mountOptions = [
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
mountpoint = "/nix";
|
||||
};
|
||||
# This subvolume will be created but not mounted
|
||||
@@ -74,4 +77,3 @@
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
+4
-3
@@ -28,6 +28,7 @@
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
luks = {
|
||||
uuid = "f0f0f0f0-f0f0-f0f0-f0f0-f0f0f0f0f0f0";
|
||||
start = "1M";
|
||||
size = "100%";
|
||||
content = {
|
||||
@@ -106,13 +107,13 @@
|
||||
lvm_type = "mirror";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "ext4";
|
||||
mountpoint = "/ext4_on_lvm";
|
||||
format = "exfat";
|
||||
mountpoint = "/exfat_on_lvm";
|
||||
mountOptions = [
|
||||
"defaults"
|
||||
];
|
||||
postMountHook = ''
|
||||
touch /mnt/ext4_on_lvm/file-from-postMountHook
|
||||
touch /mnt/exfat_on_lvm/file-from-postMountHook
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [ "umask=0077" ];
|
||||
};
|
||||
};
|
||||
"name with spaces" = {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
# Example to create a GPT partition but doesn't format it
|
||||
{
|
||||
disko.devices = {
|
||||
disk = {
|
||||
main = {
|
||||
device = "/dev/vdb";
|
||||
type = "disk";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
ESP = {
|
||||
type = "EF00";
|
||||
size = "100M";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [ "umask=0077" ];
|
||||
};
|
||||
};
|
||||
empty = {
|
||||
size = "1G";
|
||||
};
|
||||
root = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "ext4";
|
||||
mountpoint = "/";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [ "umask=0077" ];
|
||||
};
|
||||
}
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [ "umask=0077" ];
|
||||
};
|
||||
}
|
||||
{
|
||||
@@ -37,4 +38,3 @@
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -35,15 +35,24 @@
|
||||
subvolumes = {
|
||||
"/root" = {
|
||||
mountpoint = "/";
|
||||
mountOptions = [ "compress=zstd" "noatime" ];
|
||||
mountOptions = [
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
};
|
||||
"/home" = {
|
||||
mountpoint = "/home";
|
||||
mountOptions = [ "compress=zstd" "noatime" ];
|
||||
mountOptions = [
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
};
|
||||
"/nix" = {
|
||||
mountpoint = "/nix";
|
||||
mountOptions = [ "compress=zstd" "noatime" ];
|
||||
mountOptions = [
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
};
|
||||
"/swap" = {
|
||||
mountpoint = "/.swapvol";
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [ "umask=0077" ];
|
||||
};
|
||||
};
|
||||
raid1 = {
|
||||
@@ -55,4 +56,3 @@
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [ "umask=0077" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{ pkgs
|
||||
, lib
|
||||
, ...
|
||||
{
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
# We just import from the repository for testing here:
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
# Example to create a bios compatible gpt partition
|
||||
{ disks ? [ "/dev/vdb" ], lib, ... }: {
|
||||
{
|
||||
disks ? [ "/dev/vdb" ],
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
{
|
||||
disko.devices = {
|
||||
disk = lib.genAttrs disks (device: {
|
||||
name = lib.replaceStrings [ "/" ] [ "_" ] device;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
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"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
{
|
||||
disko.devices = {
|
||||
disk = {
|
||||
root = {
|
||||
type = "disk";
|
||||
device = "/dev/nvme0n1";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
ESP = {
|
||||
size = "1G";
|
||||
type = "EF00";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [ "nofail" ];
|
||||
};
|
||||
};
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "zroot";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
zpool = {
|
||||
zroot = {
|
||||
type = "zpool";
|
||||
rootFsOptions = {
|
||||
mountpoint = "none";
|
||||
compression = "zstd";
|
||||
acltype = "posixacl";
|
||||
xattr = "sa";
|
||||
"com.sun:auto-snapshot" = "true";
|
||||
};
|
||||
options.ashift = "12";
|
||||
datasets = {
|
||||
"root" = {
|
||||
type = "zfs_fs";
|
||||
options = {
|
||||
encryption = "aes-256-gcm";
|
||||
keyformat = "passphrase";
|
||||
#keylocation = "file:///tmp/secret.key";
|
||||
keylocation = "prompt";
|
||||
};
|
||||
mountpoint = "/";
|
||||
|
||||
};
|
||||
"root/nix" = {
|
||||
type = "zfs_fs";
|
||||
options.mountpoint = "/nix";
|
||||
mountpoint = "/nix";
|
||||
};
|
||||
|
||||
# README MORE: https://wiki.archlinux.org/title/ZFS#Swap_volume
|
||||
"root/swap" = {
|
||||
type = "zfs_volume";
|
||||
size = "10M";
|
||||
content = {
|
||||
type = "swap";
|
||||
};
|
||||
options = {
|
||||
volblocksize = "4096";
|
||||
compression = "zle";
|
||||
logbias = "throughput";
|
||||
sync = "always";
|
||||
primarycache = "metadata";
|
||||
secondarycache = "none";
|
||||
"com.sun:auto-snapshot" = "false";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
# systemd will mount an ext4 filesystem at / and zfs will mount the dataset underneath it
|
||||
{
|
||||
disko.devices = {
|
||||
disk = {
|
||||
|
||||
+212
-12
@@ -1,9 +1,9 @@
|
||||
{
|
||||
disko.devices = {
|
||||
disk = {
|
||||
x = {
|
||||
data1 = {
|
||||
type = "disk";
|
||||
device = "/dev/sdx";
|
||||
device = "/dev/vda";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
@@ -27,9 +27,9 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
y = {
|
||||
data2 = {
|
||||
type = "disk";
|
||||
device = "/dev/sdy";
|
||||
device = "/dev/vdb";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
@@ -43,9 +43,169 @@
|
||||
};
|
||||
};
|
||||
};
|
||||
z = {
|
||||
data3 = {
|
||||
type = "disk";
|
||||
device = "/dev/sdz";
|
||||
device = "/dev/vdc";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "zroot";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
spare = {
|
||||
type = "disk";
|
||||
device = "/dev/vdd";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "zroot";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
log1 = {
|
||||
type = "disk";
|
||||
device = "/dev/vde";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "zroot";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
log2 = {
|
||||
type = "disk";
|
||||
device = "/dev/vdf";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "zroot";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
log3 = {
|
||||
type = "disk";
|
||||
device = "/dev/vdg";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "zroot";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
dedup1 = {
|
||||
type = "disk";
|
||||
device = "/dev/vdh";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "zroot";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
dedup2 = {
|
||||
type = "disk";
|
||||
device = "/dev/vdi";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "zroot";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
dedup3 = {
|
||||
type = "disk";
|
||||
device = "/dev/vdj";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "zroot";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
special1 = {
|
||||
type = "disk";
|
||||
device = "/dev/vdk";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "zroot";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
special2 = {
|
||||
type = "disk";
|
||||
device = "/dev/vdl";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
zfs = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "zfs";
|
||||
pool = "zroot";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
special3 = {
|
||||
type = "disk";
|
||||
device = "/dev/vdm";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
@@ -61,7 +221,7 @@
|
||||
};
|
||||
cache = {
|
||||
type = "disk";
|
||||
device = "/dev/vdc";
|
||||
device = "/dev/vdn";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
@@ -83,17 +243,57 @@
|
||||
topology = {
|
||||
type = "topology";
|
||||
vdev = [
|
||||
{
|
||||
# This syntax expects a disk called 'data3' 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" ];
|
||||
}
|
||||
{
|
||||
mode = "mirror";
|
||||
members = [
|
||||
"x"
|
||||
"y"
|
||||
"data2"
|
||||
"data3"
|
||||
];
|
||||
}
|
||||
];
|
||||
special = {
|
||||
members = [ "z" ];
|
||||
};
|
||||
spare = [ "spare" ];
|
||||
log = [
|
||||
{
|
||||
mode = "mirror";
|
||||
members = [
|
||||
"log1"
|
||||
"log2"
|
||||
];
|
||||
}
|
||||
{
|
||||
members = [ "log3" ];
|
||||
}
|
||||
];
|
||||
dedup = [
|
||||
{
|
||||
mode = "mirror";
|
||||
members = [
|
||||
"dedup1"
|
||||
"dedup2"
|
||||
];
|
||||
}
|
||||
{
|
||||
members = [ "dedup3" ];
|
||||
}
|
||||
];
|
||||
special = [
|
||||
{
|
||||
mode = "mirror";
|
||||
members = [
|
||||
"special1"
|
||||
"special2"
|
||||
];
|
||||
}
|
||||
{
|
||||
members = [ "special3" ];
|
||||
}
|
||||
];
|
||||
cache = [ "cache" ];
|
||||
};
|
||||
};
|
||||
|
||||
+19
-1
@@ -72,7 +72,7 @@
|
||||
options.mountpoint = "legacy";
|
||||
mountpoint = "/zfs_legacy_fs";
|
||||
};
|
||||
zfs_testvolume = {
|
||||
zfs_volume = {
|
||||
type = "zfs_volume";
|
||||
size = "10M";
|
||||
content = {
|
||||
@@ -81,6 +81,24 @@
|
||||
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 = {
|
||||
type = "zfs_fs";
|
||||
options = {
|
||||
|
||||
Generated
+3
-3
@@ -2,11 +2,11 @@
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1725194671,
|
||||
"narHash": "sha256-tLGCFEFTB5TaOKkpfw3iYT9dnk4awTP/q4w+ROpMfuw=",
|
||||
"lastModified": 1738136902,
|
||||
"narHash": "sha256-pUvLijVGARw4u793APze3j6mU1Zwdtz7hGkGGkD87qw=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "b833ff01a0d694b910daca6e2ff4a3f26dee478c",
|
||||
"rev": "9a5db3142ce450045840cc8d832b13b8a2018e0c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
#inputs.nixpkgs.url = "nixpkgs";
|
||||
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
|
||||
outputs = { self, nixpkgs, ... }:
|
||||
outputs =
|
||||
{ self, nixpkgs, ... }:
|
||||
let
|
||||
lib = nixpkgs.lib;
|
||||
supportedSystems = [
|
||||
@@ -19,14 +20,17 @@
|
||||
|
||||
versionInfo = import ./version.nix;
|
||||
version = versionInfo.version + (lib.optionalString (!versionInfo.released) "-dirty");
|
||||
|
||||
diskoLib = import ./lib {
|
||||
inherit (nixpkgs) lib;
|
||||
};
|
||||
in
|
||||
{
|
||||
nixosModules.default = self.nixosModules.disko; # convention
|
||||
nixosModules.disko.imports = [ ./module.nix ];
|
||||
lib = import ./lib {
|
||||
inherit (nixpkgs) lib;
|
||||
};
|
||||
packages = forAllSystems (system:
|
||||
nixosModules.disko = ./module.nix;
|
||||
lib = diskoLib;
|
||||
packages = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in
|
||||
@@ -39,38 +43,50 @@
|
||||
default = self.packages.${system}.disko;
|
||||
|
||||
create-release = pkgs.callPackage ./scripts/create-release.nix { };
|
||||
} // pkgs.lib.optionalAttrs (!pkgs.buildPlatform.isRiscV64) {
|
||||
}
|
||||
// pkgs.lib.optionalAttrs (!pkgs.stdenv.buildPlatform.isRiscV64) {
|
||||
disko-doc = pkgs.callPackage ./doc.nix { };
|
||||
});
|
||||
}
|
||||
);
|
||||
# TODO: disable bios-related tests on aarch64...
|
||||
# Run checks: nix flake check -L
|
||||
checks = forAllSystems (system:
|
||||
checks = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
# FIXME: aarch64-linux seems to hang on boot
|
||||
nixosTests = lib.optionalAttrs pkgs.hostPlatform.isx86_64 (import ./tests {
|
||||
nixosTests = lib.optionalAttrs pkgs.stdenv.hostPlatform.isx86_64 (
|
||||
import ./tests {
|
||||
inherit pkgs;
|
||||
makeTest = import (pkgs.path + "/nixos/tests/make-test-python.nix");
|
||||
eval-config = import (pkgs.path + "/nixos/lib/eval-config.nix");
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
disko-install = pkgs.callPackage ./tests/disko-install {
|
||||
inherit self;
|
||||
diskoVersion = version;
|
||||
};
|
||||
|
||||
shellcheck = pkgs.runCommand "shellcheck" { nativeBuildInputs = [ pkgs.shellcheck ]; } ''
|
||||
cd ${./.}
|
||||
shellcheck disk-deactivate/disk-deactivate disko
|
||||
jsonTypes = pkgs.writeTextFile {
|
||||
name = "jsonTypes";
|
||||
text = (builtins.toJSON diskoLib.jsonTypes);
|
||||
};
|
||||
|
||||
treefmt = pkgs.runCommand "treefmt" { } ''
|
||||
${self.formatter.${system}}/bin/treefmt --ci --working-dir ${self}
|
||||
touch $out
|
||||
'';
|
||||
in
|
||||
# FIXME: aarch64-linux seems to hang on boot
|
||||
lib.optionalAttrs pkgs.hostPlatform.isx86_64 (nixosTests // { inherit disko-install; }) //
|
||||
pkgs.lib.optionalAttrs (!pkgs.buildPlatform.isRiscV64 && !pkgs.hostPlatform.isx86_32) {
|
||||
inherit shellcheck;
|
||||
lib.optionalAttrs pkgs.stdenv.hostPlatform.isx86_64 (nixosTests // { inherit disko-install; })
|
||||
//
|
||||
pkgs.lib.optionalAttrs (!pkgs.stdenv.buildPlatform.isRiscV64 && !pkgs.stdenv.hostPlatform.isx86_32)
|
||||
{
|
||||
inherit jsonTypes treefmt;
|
||||
inherit (self.packages.${system}) disko-doc;
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
nixosConfigurations.testmachine = lib.nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
@@ -80,72 +96,28 @@
|
||||
./module.nix
|
||||
];
|
||||
};
|
||||
formatter = forAllSystems (system:
|
||||
formatter = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in
|
||||
pkgs.writeShellApplication {
|
||||
name = "format";
|
||||
runtimeInputs = with pkgs; [
|
||||
nixpkgs-fmt
|
||||
deno
|
||||
deadnix
|
||||
name = "treefmt";
|
||||
text = ''treefmt "$@"'';
|
||||
runtimeInputs = [
|
||||
pkgs.deadnix
|
||||
pkgs.nixfmt-rfc-style
|
||||
pkgs.shellcheck
|
||||
pkgs.treefmt
|
||||
];
|
||||
text = ''
|
||||
showUsage() {
|
||||
cat <<EOF
|
||||
Usage: $0 [OPTIONS] FILES...
|
||||
-c, --check Only check formatting, do not modify files.
|
||||
-h, --help Show this help message.
|
||||
EOF
|
||||
}
|
||||
|
||||
check=
|
||||
files=()
|
||||
|
||||
parseArgs() {
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-h | --help)
|
||||
showUsage
|
||||
exit 0
|
||||
;;
|
||||
-c | --check)
|
||||
check=1
|
||||
;;
|
||||
*)
|
||||
files+=("$1")
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [[ ''${#files[@]} -eq 0 ]]; then
|
||||
files=(.)
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
parseArgs "$@"
|
||||
|
||||
if [[ -z "$check" ]]; then
|
||||
set -o xtrace
|
||||
|
||||
nixpkgs-fmt -- "''${files[@]}"
|
||||
deno fmt -- "''${files[@]}"
|
||||
deadnix --edit -- "''${files[@]}"
|
||||
else
|
||||
set -o xtrace
|
||||
|
||||
nixpkgs-fmt --check -- "''${files[@]}"
|
||||
deno fmt --check -- "''${files[@]}"
|
||||
deadnix -- "''${files[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
||||
'';
|
||||
}
|
||||
);
|
||||
devShells = forAllSystems (system: {
|
||||
default = nixpkgs.legacyPackages.${system}.mkShell {
|
||||
packages = [
|
||||
self.formatter.${system}
|
||||
];
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
+10
-12
@@ -1,10 +1,10 @@
|
||||
{ flake
|
||||
, flakeAttr
|
||||
, diskMappings
|
||||
, extraSystemConfig ? "{}"
|
||||
, writeEfiBootEntries ? false
|
||||
, rootMountPoint ? "/mnt"
|
||||
,
|
||||
{
|
||||
flake,
|
||||
flakeAttr,
|
||||
diskMappings,
|
||||
extraSystemConfig ? "{}",
|
||||
writeEfiBootEntries ? false,
|
||||
rootMountPoint ? "/mnt",
|
||||
}:
|
||||
let
|
||||
originalSystem = (builtins.getFlake "${flake}").nixosConfigurations."${flakeAttr}";
|
||||
@@ -17,8 +17,7 @@ let
|
||||
else
|
||||
throw "No device passed for disk '${name}'. Pass `--disk ${name} /dev/name` via commandline";
|
||||
|
||||
modifiedDisks = builtins.mapAttrs
|
||||
(
|
||||
modifiedDisks = builtins.mapAttrs (
|
||||
name: value:
|
||||
let
|
||||
dev = deviceName name;
|
||||
@@ -30,8 +29,7 @@ let
|
||||
device = dev;
|
||||
};
|
||||
}
|
||||
)
|
||||
originalSystem.config.disko.devices.disk;
|
||||
) originalSystem.config.disko.devices.disk;
|
||||
|
||||
# filter all nixos module internal attributes
|
||||
cleanedDisks = lib.filterAttrsRecursive (n: _: !lib.hasPrefix "_" n) modifiedDisks;
|
||||
@@ -51,7 +49,7 @@ let
|
||||
{ lib, ... }:
|
||||
{
|
||||
boot.loader.efi.canTouchEfiVariables = lib.mkVMOverride writeEfiBootEntries;
|
||||
boot.loader.grub.devices = lib.mkVMOverride diskoSystem.config.boot.loader.grub.devices;
|
||||
boot.loader.grub.devices = lib.mkVMOverride (lib.attrValues diskMappings);
|
||||
imports = [
|
||||
({ _file = "disko-install --system-config"; } // (builtins.fromJSON extraSystemConfig))
|
||||
];
|
||||
|
||||
+181
@@ -0,0 +1,181 @@
|
||||
{
|
||||
lib,
|
||||
diskoLib,
|
||||
pkgs,
|
||||
imagePkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
# from https://github.com/NixOS/nixpkgs/blob/851f7fc119e9597c26cc43e10938ce7272d0af9d/nixos/modules/system/boot/binfmt.nix
|
||||
makeBinfmtLine =
|
||||
{
|
||||
name,
|
||||
recognitionType,
|
||||
offset,
|
||||
magicOrExtension,
|
||||
mask,
|
||||
preserveArgvZero,
|
||||
openBinary,
|
||||
matchCredentials,
|
||||
fixBinary,
|
||||
interpreter,
|
||||
...
|
||||
}:
|
||||
let
|
||||
type = if recognitionType == "magic" then "M" else "E";
|
||||
offset' = toString offset;
|
||||
mask' = toString mask;
|
||||
flags =
|
||||
with lib;
|
||||
if !(matchCredentials -> openBinary) then
|
||||
throw "boot.binfmt.registrations.${name}: you can't specify openBinary = false when matchCredentials = true."
|
||||
else
|
||||
optionalString preserveArgvZero "P"
|
||||
+ optionalString (openBinary && !matchCredentials) "O"
|
||||
+ optionalString matchCredentials "C"
|
||||
+ optionalString fixBinary "F";
|
||||
in
|
||||
":${name}:${type}:${offset'}:${magicOrExtension}:${mask'}:${builtins.trace interpreter interpreter}:${flags}";
|
||||
magics = {
|
||||
armv6l-linux = {
|
||||
magicOrExtension = ''\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\x00\xff\xfe\xff\xff\xff'';
|
||||
};
|
||||
armv7l-linux = {
|
||||
magicOrExtension = ''\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\x00\xff\xfe\xff\xff\xff'';
|
||||
};
|
||||
aarch64-linux = {
|
||||
magicOrExtension = ''\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\x00\xff\xfe\xff\xff\xff'';
|
||||
};
|
||||
aarch64_be-linux = {
|
||||
magicOrExtension = ''\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'';
|
||||
};
|
||||
i386-linux = {
|
||||
magicOrExtension = ''\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'';
|
||||
};
|
||||
i486-linux = {
|
||||
magicOrExtension = ''\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'';
|
||||
};
|
||||
i586-linux = {
|
||||
magicOrExtension = ''\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'';
|
||||
};
|
||||
i686-linux = {
|
||||
magicOrExtension = ''\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'';
|
||||
};
|
||||
x86_64-linux = {
|
||||
magicOrExtension = ''\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'';
|
||||
};
|
||||
alpha-linux = {
|
||||
magicOrExtension = ''\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'';
|
||||
};
|
||||
sparc64-linux = {
|
||||
magicOrExtension = ''\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'';
|
||||
};
|
||||
sparc-linux = {
|
||||
magicOrExtension = ''\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x12'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'';
|
||||
};
|
||||
powerpc-linux = {
|
||||
magicOrExtension = ''\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'';
|
||||
};
|
||||
powerpc64-linux = {
|
||||
magicOrExtension = ''\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'';
|
||||
};
|
||||
powerpc64le-linux = {
|
||||
magicOrExtension = ''\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x15\x00'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\x00'';
|
||||
};
|
||||
mips-linux = {
|
||||
magicOrExtension = ''\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20'';
|
||||
};
|
||||
mipsel-linux = {
|
||||
magicOrExtension = ''\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00'';
|
||||
};
|
||||
mips64-linux = {
|
||||
magicOrExtension = ''\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'';
|
||||
};
|
||||
mips64el-linux = {
|
||||
magicOrExtension = ''\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'';
|
||||
};
|
||||
mips64-linuxabin32 = {
|
||||
magicOrExtension = ''\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20'';
|
||||
};
|
||||
mips64el-linuxabin32 = {
|
||||
magicOrExtension = ''\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00'';
|
||||
};
|
||||
riscv32-linux = {
|
||||
magicOrExtension = ''\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'';
|
||||
};
|
||||
riscv64-linux = {
|
||||
magicOrExtension = ''\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xf3\x00'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'';
|
||||
};
|
||||
loongarch64-linux = {
|
||||
magicOrExtension = ''\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02\x01'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\xfc\x00\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff'';
|
||||
};
|
||||
wasm32-wasi = {
|
||||
magicOrExtension = ''\x00asm'';
|
||||
mask = ''\xff\xff\xff\xff'';
|
||||
};
|
||||
wasm64-wasi = {
|
||||
magicOrExtension = ''\x00asm'';
|
||||
mask = ''\xff\xff\xff\xff'';
|
||||
};
|
||||
s390x-linux = {
|
||||
magicOrExtension = ''\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16'';
|
||||
mask = ''\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff'';
|
||||
};
|
||||
x86_64-windows.magicOrExtension = "MZ";
|
||||
i686-windows.magicOrExtension = "MZ";
|
||||
};
|
||||
in
|
||||
{
|
||||
binfmtRegistration =
|
||||
let
|
||||
system = imagePkgs.stdenv.hostPlatform.system;
|
||||
enabled = system != pkgs.stdenv.hostPlatform.system;
|
||||
elaborated = lib.systems.elaborate { inherit system; };
|
||||
useStaticEmulator = true; # needed for chroot
|
||||
interpreter = elaborated.emulator (if useStaticEmulator then pkgs.pkgsStatic else pkgs);
|
||||
|
||||
inherit (elaborated) qemuArch;
|
||||
isQemu = "qemu-${qemuArch}" == baseNameOf interpreter;
|
||||
in
|
||||
makeBinfmtLine (
|
||||
{
|
||||
name = system;
|
||||
inherit interpreter;
|
||||
recognitionType = "magic";
|
||||
offset = null;
|
||||
openBinary = false;
|
||||
matchCredentials = false;
|
||||
|
||||
preserveArgvZero = isQemu;
|
||||
|
||||
fixBinary = useStaticEmulator;
|
||||
}
|
||||
// (magics.${system} or (throw "Cannot create binfmt registration for system ${system}"))
|
||||
);
|
||||
systemsAreDifferent = imagePkgs.stdenv.hostPlatform.system != pkgs.stdenv.hostPlatform.system;
|
||||
}
|
||||
+649
-138
File diff suppressed because it is too large.
Load diff
+12
-6
@@ -1,8 +1,16 @@
|
||||
{ diskoLib, modulesPath, config, pkgs, lib, ... }:
|
||||
{
|
||||
diskoLib,
|
||||
modulesPath,
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
vm_disko = (diskoLib.testLib.prepareDiskoConfig config diskoLib.testLib.devices).disko;
|
||||
cfg_ = (lib.evalModules {
|
||||
cfg_ =
|
||||
(lib.evalModules {
|
||||
modules = lib.singleton {
|
||||
# _file = toString input;
|
||||
imports = lib.singleton { disko.devices = vm_disko.devices; };
|
||||
@@ -26,13 +34,11 @@ let
|
||||
deviceExtraOpts.bootindex = "1";
|
||||
deviceExtraOpts.serial = "root";
|
||||
};
|
||||
otherDisks = map
|
||||
(disk: {
|
||||
otherDisks = map (disk: {
|
||||
name = disk.name;
|
||||
file = ''"$tmp"/${lib.escapeShellArg disk.name}.qcow2'';
|
||||
driveExtraOpts.werror = "report";
|
||||
})
|
||||
(builtins.tail disks);
|
||||
}) (builtins.tail disks);
|
||||
|
||||
diskoBasedConfiguration = {
|
||||
# generated from disko config
|
||||
|
||||
+102
-43
@@ -1,9 +1,11 @@
|
||||
{ config
|
||||
, diskoLib
|
||||
, lib
|
||||
, extendModules
|
||||
, options
|
||||
, ...
|
||||
{
|
||||
config,
|
||||
diskoLib,
|
||||
lib,
|
||||
extendModules,
|
||||
options,
|
||||
imagePkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
diskoCfg = config.disko;
|
||||
@@ -12,19 +14,45 @@ let
|
||||
checked = diskoCfg.checkScripts;
|
||||
|
||||
configSupportsZfs = config.boot.supportedFilesystems.zfs or false;
|
||||
vmTools = pkgs.vmTools.override
|
||||
binfmt = diskoLib.binfmt {
|
||||
inherit
|
||||
diskoLib
|
||||
lib
|
||||
pkgs
|
||||
imagePkgs
|
||||
;
|
||||
};
|
||||
binfmtSetup = lib.optionalString (cfg.enableBinfmt && binfmt.systemsAreDifferent) ''
|
||||
mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
|
||||
${pkgs.systemdMinimal}/lib/systemd/systemd-binfmt <(echo ${lib.strings.escapeShellArg binfmt.binfmtRegistration})
|
||||
'';
|
||||
|
||||
vmTools = pkgs.vmTools.override (
|
||||
{
|
||||
rootModules = [ "9p" "9pnet_virtio" "virtio_pci" "virtio_blk" ]
|
||||
rootModules =
|
||||
[
|
||||
"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")
|
||||
++ cfg.extraRootModules;
|
||||
kernel = pkgs.aggregateModules
|
||||
(with cfg.kernelPackages; [ kernel ]
|
||||
++ lib.optional (lib.elem "zfs" cfg.extraRootModules || configSupportsZfs) zfs);
|
||||
kernel = pkgs.aggregateModules (
|
||||
[ cfg.kernelPackages.kernel ]
|
||||
++ lib.optional (
|
||||
lib.elem "zfs" cfg.extraRootModules || configSupportsZfs
|
||||
) cfg.kernelPackages.${config.boot.zfs.package.kernelModuleAttribute}
|
||||
);
|
||||
}
|
||||
// lib.optionalAttrs (diskoLib.vmToolsSupportsCustomQemu pkgs)
|
||||
{
|
||||
// lib.optionalAttrs (diskoLib.vmToolsSupportsCustomQemu lib) {
|
||||
customQemu = cfg.qemu;
|
||||
};
|
||||
}
|
||||
);
|
||||
cleanedConfig = diskoLib.testLib.prepareDiskoConfig config diskoLib.testLib.devices;
|
||||
systemToInstall = extendModules {
|
||||
modules = [
|
||||
@@ -36,7 +64,24 @@ let
|
||||
}
|
||||
];
|
||||
};
|
||||
dependencies = with pkgs; [
|
||||
systemToInstallNative =
|
||||
if binfmt.systemsAreDifferent then
|
||||
extendModules {
|
||||
modules = [
|
||||
cfg.extraConfig
|
||||
{
|
||||
disko.testMode = true;
|
||||
disko.devices = lib.mkForce cleanedConfig.disko.devices;
|
||||
boot.loader.grub.devices = lib.mkForce cleanedConfig.boot.loader.grub.devices;
|
||||
nixpkgs.hostPlatform = lib.mkForce pkgs.stdenv.hostPlatform;
|
||||
}
|
||||
];
|
||||
}
|
||||
else
|
||||
systemToInstall;
|
||||
dependencies =
|
||||
with pkgs;
|
||||
[
|
||||
bash
|
||||
coreutils
|
||||
gnused
|
||||
@@ -45,20 +90,22 @@ let
|
||||
nix
|
||||
util-linux
|
||||
findutils
|
||||
] ++ cfg.extraDependencies;
|
||||
kmod
|
||||
]
|
||||
++ cfg.extraDependencies;
|
||||
preVM = ''
|
||||
${lib.concatMapStringsSep "\n" (disk: "${pkgs.qemu}/bin/qemu-img create -f ${imageFormat} ${disk.imageName}.${imageFormat} ${disk.imageSize}") (lib.attrValues diskoCfg.devices.disk)}
|
||||
# shellcheck disable=SC2154
|
||||
mkdir -p "$out"
|
||||
${lib.concatMapStringsSep "\n" (
|
||||
disk:
|
||||
# shellcheck disable=SC2154
|
||||
"${pkgs.qemu}/bin/qemu-img create -f ${imageFormat} \"$out/${disk.imageName}.${imageFormat}\" ${disk.imageSize}"
|
||||
) (lib.attrValues diskoCfg.devices.disk)}
|
||||
# This makes disko work, when canTouchEfiVariables is set to true.
|
||||
# Technically these boot entries will no be persisted this way, but
|
||||
# in most cases this is OK, because we can rely on the standard location for UEFI executables.
|
||||
install -m600 ${pkgs.OVMF.variables} efivars.fd
|
||||
'';
|
||||
postVM = ''
|
||||
# shellcheck disable=SC2154
|
||||
mkdir -p "$out"
|
||||
${lib.concatMapStringsSep "\n" (disk: "mv ${disk.imageName}.${imageFormat} \"$out\"/${disk.imageName}.${imageFormat}") (lib.attrValues diskoCfg.devices.disk)}
|
||||
${cfg.extraPostVM}
|
||||
'';
|
||||
|
||||
closureInfo = pkgs.closureInfo {
|
||||
rootPaths = [ systemToInstall.config.system.build.toplevel ];
|
||||
@@ -73,7 +120,7 @@ let
|
||||
ln -sfn /proc/self/fd/2 /dev/stderr
|
||||
mkdir -p /etc/udev
|
||||
mount -t efivarfs none /sys/firmware/efi/efivars
|
||||
ln -sfn ${systemToInstall.config.system.build.etc}/etc/udev/rules.d /etc/udev/rules.d
|
||||
ln -sfn ${systemToInstallNative.config.system.build.etc}/etc/udev/rules.d /etc/udev/rules.d
|
||||
mkdir -p /dev/.mdadm
|
||||
${pkgs.systemdMinimal}/lib/systemd/systemd-udevd --daemon
|
||||
partprobe
|
||||
@@ -83,39 +130,43 @@ let
|
||||
${lib.optionalString diskoCfg.testMode ''
|
||||
export IN_DISKO_TEST=1
|
||||
''}
|
||||
${systemToInstall.config.system.build.diskoScript}
|
||||
${lib.getExe systemToInstallNative.config.system.build.destroyFormatMount} --yes-wipe-all-disks
|
||||
'';
|
||||
|
||||
installer = lib.optionalString cfg.copyNixStore ''
|
||||
${binfmtSetup}
|
||||
# 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
|
||||
xargs cp --recursive --target ${systemToInstall.config.disko.rootMountPoint}/nix/store < ${closureInfo}/store-paths
|
||||
time xargs cp --recursive --target ${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 ${systemToInstall.config.disko.rootMountPoint}
|
||||
'';
|
||||
|
||||
QEMU_OPTS = lib.concatStringsSep " " ([
|
||||
QEMU_OPTS = lib.concatStringsSep " " (
|
||||
[
|
||||
"-drive if=pflash,format=raw,unit=0,readonly=on,file=${pkgs.OVMF.firmware}"
|
||||
"-drive if=pflash,format=raw,unit=1,file=efivars.fd"
|
||||
] ++ builtins.map
|
||||
(disk:
|
||||
"-drive file=${disk.imageName}.${imageFormat},if=virtio,cache=unsafe,werror=report,format=${imageFormat}"
|
||||
)
|
||||
(lib.attrValues diskoCfg.devices.disk));
|
||||
]
|
||||
++ builtins.map (
|
||||
disk:
|
||||
"-drive file=\"$out\"/${disk.imageName}.${imageFormat},if=virtio,cache=unsafe,werror=report,format=${imageFormat}"
|
||||
) (lib.attrValues diskoCfg.devices.disk)
|
||||
);
|
||||
in
|
||||
{
|
||||
system.build.diskoImages = vmTools.runInLinuxVM (pkgs.runCommand cfg.name
|
||||
{
|
||||
system.build.diskoImages = vmTools.runInLinuxVM (
|
||||
pkgs.runCommand cfg.name {
|
||||
buildInputs = dependencies;
|
||||
inherit preVM postVM QEMU_OPTS;
|
||||
inherit preVM QEMU_OPTS;
|
||||
postVM = cfg.extraPostVM;
|
||||
inherit (diskoCfg) memSize;
|
||||
}
|
||||
(partitioner + installer));
|
||||
} (binfmtSetup + partitioner + installer)
|
||||
);
|
||||
|
||||
system.build.diskoImagesScript = diskoLib.writeCheckedBash { inherit checked pkgs; } cfg.name ''
|
||||
set -efu
|
||||
@@ -139,8 +190,11 @@ in
|
||||
USAGE
|
||||
}
|
||||
|
||||
export out=$PWD
|
||||
# emulate basic build environment https://github.com/NixOS/nix/blob/fc83c6ccb3b300256508297bb92dd95e18a81213/src/nix-build/nix-build.cc#L541
|
||||
TMPDIR=$(mktemp -d); export TMPDIR
|
||||
export NIX_BUILD_TOP=$TMPDIR
|
||||
export out=$PWD
|
||||
export stdenv=${pkgs.stdenv}
|
||||
trap 'rm -rf "$TMPDIR"' EXIT
|
||||
cd "$TMPDIR"
|
||||
|
||||
@@ -177,7 +231,8 @@ in
|
||||
shift
|
||||
done
|
||||
|
||||
export preVM=${diskoLib.writeCheckedBash { inherit pkgs checked; } "preVM.sh" ''
|
||||
export preVM=${
|
||||
diskoLib.writeCheckedBash { inherit pkgs checked; } "preVM.sh" ''
|
||||
set -efu
|
||||
mv copy_before_disko copy_after_disko xchg/
|
||||
origBuilder=${pkgs.writeScript "disko-builder" ''
|
||||
@@ -200,14 +255,18 @@ in
|
||||
done
|
||||
${installer}
|
||||
''}
|
||||
echo "export origBuilder=$origBuilder" > xchg/saved-env
|
||||
echo "export origBuilder=$origBuilder" >> xchg/saved-env
|
||||
${preVM}
|
||||
''}
|
||||
export postVM=${diskoLib.writeCheckedBash { inherit pkgs checked; } "postVM.sh" postVM}
|
||||
''
|
||||
}
|
||||
export postVM=${diskoLib.writeCheckedBash { inherit pkgs checked; } "postVM.sh" cfg.extraPostVM}
|
||||
|
||||
build_memory=''${build_memory:-${builtins.toString diskoCfg.memSize}}
|
||||
# shellcheck disable=SC2016
|
||||
QEMU_OPTS=${lib.escapeShellArg QEMU_OPTS}
|
||||
QEMU_OPTS+=" -m $build_memory"
|
||||
# replace quoted $out with the actual path
|
||||
QEUM_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
|
||||
|
||||
${pkgs.bash}/bin/sh -e ${vmTools.vmRunCommand vmTools.qemuCommandLinux}
|
||||
|
||||
+134
-64
@@ -1,25 +1,34 @@
|
||||
{ lib
|
||||
, makeTest
|
||||
, eval-config
|
||||
, ...
|
||||
{
|
||||
lib,
|
||||
makeTest,
|
||||
eval-config,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
testLib = {
|
||||
# this takes a nixos config and changes the disk devices so we can run them inside the qemu test runner
|
||||
# basically changes all the disk.*.devices to something like /dev/vda or /dev/vdb etc.
|
||||
prepareDiskoConfig = cfg: devices:
|
||||
prepareDiskoConfig =
|
||||
cfg: devices:
|
||||
let
|
||||
cleanedTopLevel = lib.filterAttrsRecursive (n: _: !lib.hasPrefix "_" n) cfg;
|
||||
|
||||
preparedDisks = lib.foldlAttrs
|
||||
preparedDisks =
|
||||
lib.foldlAttrs
|
||||
(acc: n: v: {
|
||||
devices = lib.tail acc.devices;
|
||||
grub-devices = acc.grub-devices ++ (lib.optional (lib.any (part: (part.type or "") == "EF02") (lib.attrValues (v.content.partitions or { }))) (lib.head acc.devices));
|
||||
grub-devices =
|
||||
acc.grub-devices
|
||||
++ (lib.optional (lib.any (part: (part.type or "") == "EF02") (
|
||||
lib.attrValues (v.content.partitions or { })
|
||||
)) (lib.head acc.devices));
|
||||
disks = acc.disks // {
|
||||
"${n}" = v // {
|
||||
device = lib.head acc.devices;
|
||||
content = v.content // { device = lib.head acc.devices; };
|
||||
content = v.content // {
|
||||
device = lib.head acc.devices;
|
||||
};
|
||||
};
|
||||
};
|
||||
})
|
||||
@@ -30,44 +39,61 @@ let
|
||||
}
|
||||
cleanedTopLevel.disko.devices.disk;
|
||||
in
|
||||
cleanedTopLevel // {
|
||||
boot.loader.grub.devices = if (preparedDisks.grub-devices != [ ]) then preparedDisks.grub-devices else [ "nodev" ];
|
||||
cleanedTopLevel
|
||||
// {
|
||||
boot.loader.grub.devices =
|
||||
if (preparedDisks.grub-devices != [ ]) then preparedDisks.grub-devices else [ "nodev" ];
|
||||
disko.devices = cleanedTopLevel.disko.devices // {
|
||||
disk = preparedDisks.disks;
|
||||
};
|
||||
};
|
||||
|
||||
# list of devices generated inside qemu
|
||||
devices = [ "/dev/vda" "/dev/vdb" "/dev/vdc" "/dev/vdd" "/dev/vde" "/dev/vdf" ];
|
||||
devices = [
|
||||
"/dev/vda"
|
||||
"/dev/vdb"
|
||||
"/dev/vdc"
|
||||
"/dev/vdd"
|
||||
"/dev/vde"
|
||||
"/dev/vdf"
|
||||
"/dev/vdg"
|
||||
"/dev/vdh"
|
||||
"/dev/vdi"
|
||||
"/dev/vdj"
|
||||
"/dev/vdk"
|
||||
"/dev/vdl"
|
||||
"/dev/vdm"
|
||||
"/dev/vdn"
|
||||
"/dev/vdo"
|
||||
];
|
||||
|
||||
# This is the test generator for a disko test
|
||||
makeDiskoTest =
|
||||
{ name
|
||||
, disko-config
|
||||
, extendModules ? null
|
||||
, pkgs ? import <nixpkgs> { }
|
||||
, extraTestScript ? ""
|
||||
, bootCommands ? ""
|
||||
, extraInstallerConfig ? { }
|
||||
, extraSystemConfig ? { }
|
||||
, efi ? !pkgs.hostPlatform.isRiscV64
|
||||
, postDisko ? ""
|
||||
, testMode ? "module" # can be one of direct module cli
|
||||
, testBoot ? true # if we actually want to test booting or just create/mount
|
||||
{
|
||||
name,
|
||||
disko-config,
|
||||
extendModules ? null,
|
||||
pkgs ? import <nixpkgs> { },
|
||||
extraTestScript ? "",
|
||||
bootCommands ? "",
|
||||
extraInstallerConfig ? { },
|
||||
extraSystemConfig ? { },
|
||||
efi ? !pkgs.stdenv.hostPlatform.isRiscV64,
|
||||
postDisko ? "",
|
||||
testMode ? "module", # can be one of direct module cli
|
||||
testBoot ? true, # if we actually want to test booting or just create/mount
|
||||
enableOCR ? false,
|
||||
}:
|
||||
let
|
||||
makeTest' = args:
|
||||
makeTest' =
|
||||
args:
|
||||
makeTest args {
|
||||
inherit pkgs;
|
||||
inherit (pkgs) system;
|
||||
};
|
||||
# for installation we skip /dev/vda because it is the test runner disk
|
||||
|
||||
importedDiskoConfig =
|
||||
if builtins.isPath disko-config then
|
||||
import disko-config
|
||||
else
|
||||
disko-config;
|
||||
importedDiskoConfig = if builtins.isPath disko-config then import disko-config else disko-config;
|
||||
|
||||
diskoConfigWithArgs =
|
||||
if builtins.isFunction importedDiskoConfig then
|
||||
@@ -80,13 +106,16 @@ let
|
||||
testConfigBooted = testLib.prepareDiskoConfig diskoConfigWithArgs testLib.devices;
|
||||
|
||||
tsp-generator = pkgs.callPackage ../. { checked = true; };
|
||||
tsp-format = (tsp-generator.formatScript testConfigInstall) pkgs;
|
||||
tsp-mount = (tsp-generator.mountScript testConfigInstall) pkgs;
|
||||
tsp-disko = (tsp-generator.diskoScript testConfigInstall) pkgs;
|
||||
tsp-format = (tsp-generator._cliFormat testConfigInstall) pkgs;
|
||||
tsp-mount = (tsp-generator._cliMount testConfigInstall) pkgs;
|
||||
tsp-unmount = (tsp-generator._cliUnmount testConfigInstall) pkgs;
|
||||
tsp-disko = (tsp-generator._cliDestroyFormatMount testConfigInstall) pkgs;
|
||||
tsp-config = tsp-generator.config testConfigBooted;
|
||||
num-disks = builtins.length (lib.attrNames testConfigBooted.disko.devices.disk);
|
||||
|
||||
installed-system = { config, ... }: {
|
||||
installed-system =
|
||||
{ config, ... }:
|
||||
{
|
||||
imports = [
|
||||
(lib.optionalAttrs (testMode == "direct") tsp-config)
|
||||
(lib.optionalAttrs (testMode == "module") {
|
||||
@@ -114,18 +143,24 @@ let
|
||||
inherit (pkgs) system;
|
||||
};
|
||||
|
||||
installedTopLevel = ((if extendModules != null then extendModules else installed-system-eval.extendModules) {
|
||||
installedTopLevel =
|
||||
((if extendModules != null then extendModules else installed-system-eval.extendModules) {
|
||||
modules = [
|
||||
({ config, ... }: {
|
||||
(
|
||||
{ config, ... }:
|
||||
{
|
||||
imports = [
|
||||
extraSystemConfig
|
||||
({ modulesPath, ... }: {
|
||||
(
|
||||
{ modulesPath, ... }:
|
||||
{
|
||||
imports = [
|
||||
(modulesPath + "/testing/test-instrumentation.nix") # we need these 2 modules always to be able to run the tests
|
||||
(modulesPath + "/profiles/qemu-guest.nix")
|
||||
];
|
||||
disko.devices = lib.mkForce testConfigBooted.disko.devices;
|
||||
})
|
||||
}
|
||||
)
|
||||
];
|
||||
|
||||
# since we boot on a different machine, the efi payload needs to be portable
|
||||
@@ -138,7 +173,11 @@ let
|
||||
device = "nix-store";
|
||||
fsType = "9p";
|
||||
neededForBoot = true;
|
||||
options = [ "trans=virtio" "version=9p2000.L" "cache=loose" ];
|
||||
options = [
|
||||
"trans=virtio"
|
||||
"version=9p2000.L"
|
||||
"cache=loose"
|
||||
];
|
||||
};
|
||||
boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms
|
||||
|
||||
@@ -148,7 +187,8 @@ let
|
||||
|
||||
assertions = [
|
||||
{
|
||||
assertion = builtins.length config.boot.loader.grub.mirroredBoots > 1 -> config.boot.loader.grub.devices == [ ];
|
||||
assertion =
|
||||
builtins.length config.boot.loader.grub.mirroredBoots > 1 -> config.boot.loader.grub.devices == [ ];
|
||||
message = ''
|
||||
When using `--vm-test` in combination with `mirroredBoots`,
|
||||
it is necessary to configure `boot.loader.grub.devices` as an empty list by setting `boot.loader.grub.devices = lib.mkForce [];`.
|
||||
@@ -156,15 +196,20 @@ let
|
||||
'';
|
||||
}
|
||||
];
|
||||
})
|
||||
}
|
||||
)
|
||||
];
|
||||
}).config.system.build.toplevel;
|
||||
|
||||
in
|
||||
makeTest' {
|
||||
name = "disko-${name}";
|
||||
meta.timeout = 600; # 10 minutes
|
||||
inherit enableOCR;
|
||||
|
||||
nodes.machine = { pkgs, ... }: {
|
||||
nodes.machine =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
imports = [
|
||||
(lib.optionalAttrs (testMode == "module") {
|
||||
imports = [
|
||||
@@ -179,17 +224,37 @@ let
|
||||
extraInstallerConfig
|
||||
|
||||
# from base.nix
|
||||
({ config, ... }: {
|
||||
(
|
||||
{ config, ... }:
|
||||
{
|
||||
boot.supportedFilesystems =
|
||||
[ "btrfs" "cifs" "f2fs" "jfs" "ntfs" "reiserfs" "vfat" "xfs" ] ++
|
||||
lib.optional (config.networking.hostId != null && lib.meta.availableOn pkgs.stdenv.hostPlatform config.boot.zfs.package) "zfs";
|
||||
})
|
||||
[
|
||||
"btrfs"
|
||||
"cifs"
|
||||
"f2fs"
|
||||
"jfs"
|
||||
"ntfs"
|
||||
"reiserfs"
|
||||
"vfat"
|
||||
"xfs"
|
||||
]
|
||||
++ lib.optional (
|
||||
config.networking.hostId != null
|
||||
&& lib.meta.availableOn pkgs.stdenv.hostPlatform config.boot.zfs.package
|
||||
) "zfs";
|
||||
}
|
||||
)
|
||||
|
||||
(if lib.versionAtLeast (lib.versions.majorMinor lib.version) "23.11" then {
|
||||
(
|
||||
if lib.versionAtLeast (lib.versions.majorMinor lib.version) "23.11" then
|
||||
{
|
||||
boot.swraid.enable = true;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
boot.initrd.services.swraid.enable = true;
|
||||
})
|
||||
}
|
||||
)
|
||||
];
|
||||
|
||||
systemd.services.mdmonitor.enable = false; # silence some weird warnings
|
||||
@@ -207,11 +272,9 @@ let
|
||||
connect-timeout = 1;
|
||||
};
|
||||
|
||||
networking.hostId = lib.mkIf
|
||||
(
|
||||
networking.hostId = lib.mkIf (
|
||||
(testConfigInstall ? networking.hostId) && (testConfigInstall.networking.hostId != null)
|
||||
)
|
||||
testConfigInstall.networking.hostId;
|
||||
) testConfigInstall.networking.hostId;
|
||||
|
||||
virtualisation.emptyDiskImages = builtins.genList (_: 4096) num-disks;
|
||||
|
||||
@@ -219,7 +282,9 @@ let
|
||||
system.build.systemToInstall = installed-system-eval;
|
||||
};
|
||||
|
||||
testScript = { nodes, ... }: ''
|
||||
testScript =
|
||||
{ nodes, ... }:
|
||||
''
|
||||
def disks(oldmachine, num_disks):
|
||||
disk_flags = []
|
||||
for i in range(num_disks):
|
||||
@@ -260,24 +325,27 @@ let
|
||||
machine.succeed("echo -n 'secretsecret' > /tmp/secret.key")
|
||||
${lib.optionalString (testMode == "direct") ''
|
||||
# running direct mode
|
||||
machine.succeed("${tsp-format}")
|
||||
machine.succeed("${tsp-mount}")
|
||||
machine.succeed("${tsp-mount}") # verify that mount is idempotent
|
||||
machine.succeed("${tsp-disko}") # verify that we can destroy and recreate
|
||||
machine.succeed("${lib.getExe tsp-format}")
|
||||
machine.succeed("${lib.getExe tsp-mount}")
|
||||
machine.succeed("${lib.getExe tsp-mount}") # verify that mount is idempotent
|
||||
machine.succeed("${lib.getExe tsp-unmount}")
|
||||
machine.succeed("${lib.getExe tsp-unmount}") # verify that umount is idempotent
|
||||
machine.succeed("${lib.getExe tsp-mount}") # verify that mount is idempotent
|
||||
machine.succeed("${lib.getExe tsp-disko} --yes-wipe-all-disks") # verify that we can destroy and recreate
|
||||
machine.succeed("mkdir -p /mnt/home")
|
||||
machine.succeed("touch /mnt/home/testfile")
|
||||
machine.succeed("${tsp-format}") # verify that format is idempotent
|
||||
machine.succeed("${lib.getExe tsp-format}") # verify that format is idempotent
|
||||
machine.succeed("test -e /mnt/home/testfile")
|
||||
''}
|
||||
${lib.optionalString (testMode == "module") ''
|
||||
# running module mode
|
||||
machine.succeed("${nodes.machine.system.build.formatScript}")
|
||||
machine.succeed("${nodes.machine.system.build.mountScript}")
|
||||
machine.succeed("${nodes.machine.system.build.mountScript}") # verify that mount is idempotent
|
||||
machine.succeed("${nodes.machine.system.build.diskoScript}") # verify that we can destroy and recreate again
|
||||
machine.succeed("${lib.getExe nodes.machine.system.build.format}")
|
||||
machine.succeed("${lib.getExe nodes.machine.system.build.mount}")
|
||||
machine.succeed("${lib.getExe nodes.machine.system.build.mount}") # verify that mount is idempotent
|
||||
machine.succeed("${lib.getExe nodes.machine.system.build.destroyFormatMount} --yes-wipe-all-disks") # verify that we can destroy and recreate again
|
||||
machine.succeed("mkdir -p /mnt/home")
|
||||
machine.succeed("touch /mnt/home/testfile")
|
||||
machine.succeed("${nodes.machine.system.build.formatScript}") # verify that format is idempotent
|
||||
machine.succeed("${lib.getExe nodes.machine.system.build.format}") # verify that format is idempotent
|
||||
machine.succeed("test -e /mnt/home/testfile")
|
||||
''}
|
||||
|
||||
@@ -288,7 +356,9 @@ let
|
||||
machine.succeed("mkdir -p /mnt/nix/store")
|
||||
machine.succeed("mount --bind /nix/store /mnt/nix/store")
|
||||
|
||||
machine.succeed("nix-store --load-db < ${pkgs.closureInfo {rootPaths = [installedTopLevel];}}/registration")
|
||||
machine.succeed("nix-store --load-db < ${
|
||||
pkgs.closureInfo { rootPaths = [ installedTopLevel ]; }
|
||||
}/registration")
|
||||
|
||||
# fix "this is not a NixOS installation"
|
||||
machine.succeed("mkdir -p /mnt/etc")
|
||||
|
||||
+86
-34
@@ -1,7 +1,19 @@
|
||||
{ config, options, diskoLib, lib, rootMountPoint, parent, device, ... }:
|
||||
{
|
||||
config,
|
||||
options,
|
||||
diskoLib,
|
||||
lib,
|
||||
rootMountPoint,
|
||||
parent,
|
||||
device,
|
||||
...
|
||||
}:
|
||||
let
|
||||
swapType = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule ({ name, ... }: {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule (
|
||||
{ name, ... }:
|
||||
{
|
||||
options = {
|
||||
size = lib.mkOption {
|
||||
type = lib.types.strMatching "^([0-9]+[KMGTP])?$";
|
||||
@@ -17,7 +29,7 @@ let
|
||||
priority = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.int;
|
||||
default = null;
|
||||
description = lib.mdDoc ''
|
||||
description = ''
|
||||
Specify the priority of the swap file. Priority is a value between 0 and 32767.
|
||||
Higher numbers indicate higher priority.
|
||||
null lets the kernel choose a priority, which will show up as a negative value.
|
||||
@@ -31,30 +43,29 @@ let
|
||||
description = "Options used to mount the swap.";
|
||||
};
|
||||
};
|
||||
}));
|
||||
}
|
||||
)
|
||||
);
|
||||
default = { };
|
||||
description = "Swap files";
|
||||
};
|
||||
|
||||
swapConfig = { mountpoint, swap }:
|
||||
swapConfig =
|
||||
{ mountpoint, swap }:
|
||||
{
|
||||
swapDevices = builtins.map
|
||||
(file: {
|
||||
swapDevices = builtins.map (file: {
|
||||
device = "${mountpoint}/${file.path}";
|
||||
inherit (file) priority options;
|
||||
})
|
||||
(lib.attrValues swap);
|
||||
}) (lib.attrValues swap);
|
||||
};
|
||||
|
||||
swapCreate = mountpoint: swap:
|
||||
lib.concatMapStringsSep
|
||||
"\n"
|
||||
(file: ''
|
||||
swapCreate =
|
||||
mountpoint: swap:
|
||||
lib.concatMapStringsSep "\n" (file: ''
|
||||
if ! test -e "${mountpoint}/${file.path}"; then
|
||||
btrfs filesystem mkswapfile --size ${file.size} "${mountpoint}/${file.path}"
|
||||
fi
|
||||
'')
|
||||
(lib.attrValues swap);
|
||||
'') (lib.attrValues swap);
|
||||
|
||||
in
|
||||
{
|
||||
@@ -80,7 +91,10 @@ in
|
||||
description = "A list of options to pass to mount.";
|
||||
};
|
||||
subvolumes = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule ({ config, ... }: {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule (
|
||||
{ config, ... }:
|
||||
{
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
@@ -110,7 +124,9 @@ in
|
||||
};
|
||||
swap = swapType;
|
||||
};
|
||||
}));
|
||||
}
|
||||
)
|
||||
);
|
||||
default = { };
|
||||
description = "Subvolumes to define for BTRFS.";
|
||||
};
|
||||
@@ -169,9 +185,13 @@ in
|
||||
inherit config options;
|
||||
default =
|
||||
let
|
||||
subvolMounts = lib.concatMapAttrs
|
||||
(_: subvol:
|
||||
lib.warnIf (subvol.mountOptions != (options.subvolumes.type.getSubOptions [ ]).mountOptions.default && subvol.mountpoint == null)
|
||||
subvolMounts = lib.concatMapAttrs (
|
||||
_: subvol:
|
||||
lib.warnIf
|
||||
(
|
||||
subvol.mountOptions != (options.subvolumes.type.getSubOptions [ ]).mountOptions.default
|
||||
&& subvol.mountpoint == null
|
||||
)
|
||||
"Subvolume ${subvol.name} has mountOptions but no mountpoint. See upgrade guide (2023-07-09 121df48)."
|
||||
lib.optionalAttrs
|
||||
(subvol.mountpoint != null)
|
||||
@@ -179,16 +199,19 @@ in
|
||||
${subvol.mountpoint} = ''
|
||||
if ! findmnt "${config.device}" "${rootMountPoint}${subvol.mountpoint}" > /dev/null 2>&1; then
|
||||
mount "${config.device}" "${rootMountPoint}${subvol.mountpoint}" \
|
||||
${lib.concatMapStringsSep " " (opt: "-o ${opt}") (subvol.mountOptions ++ [ "subvol=${subvol.name}" ])} \
|
||||
${
|
||||
lib.concatMapStringsSep " " (opt: "-o ${opt}") (subvol.mountOptions ++ [ "subvol=${subvol.name}" ])
|
||||
} \
|
||||
-o X-mount.mkdir
|
||||
fi
|
||||
'';
|
||||
}
|
||||
)
|
||||
config.subvolumes;
|
||||
) config.subvolumes;
|
||||
in
|
||||
{
|
||||
fs = subvolMounts // lib.optionalAttrs (config.mountpoint != null) {
|
||||
fs =
|
||||
subvolMounts
|
||||
// lib.optionalAttrs (config.mountpoint != null) {
|
||||
${config.mountpoint} = ''
|
||||
if ! findmnt "${config.device}" "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
|
||||
mount "${config.device}" "${rootMountPoint}${config.mountpoint}" \
|
||||
@@ -199,12 +222,39 @@ in
|
||||
};
|
||||
};
|
||||
};
|
||||
_unmount = diskoLib.mkUnmountOption {
|
||||
inherit config options;
|
||||
default =
|
||||
let
|
||||
subvolMounts = lib.concatMapAttrs (
|
||||
_: subvol:
|
||||
lib.optionalAttrs (subvol.mountpoint != null) {
|
||||
${subvol.mountpoint} = ''
|
||||
if findmnt "${config.device}" "${rootMountPoint}${subvol.mountpoint}" > /dev/null 2>&1; then
|
||||
umount "${rootMountPoint}${subvol.mountpoint}"
|
||||
fi
|
||||
'';
|
||||
}
|
||||
) config.subvolumes;
|
||||
in
|
||||
{
|
||||
fs =
|
||||
subvolMounts
|
||||
// lib.optionalAttrs (config.mountpoint != null) {
|
||||
${config.mountpoint} = ''
|
||||
if findmnt "${config.device}" "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
|
||||
umount "${rootMountPoint}${config.mountpoint}"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = [
|
||||
(map
|
||||
(subvol:
|
||||
(map (
|
||||
subvol:
|
||||
lib.optional (subvol.mountpoint != null) {
|
||||
fileSystems.${subvol.mountpoint} = {
|
||||
device = config.device;
|
||||
@@ -212,8 +262,7 @@ in
|
||||
options = subvol.mountOptions ++ [ "subvol=${subvol.name}" ];
|
||||
};
|
||||
}
|
||||
)
|
||||
(lib.attrValues config.subvolumes))
|
||||
) (lib.attrValues config.subvolumes))
|
||||
(lib.optional (config.mountpoint != null) {
|
||||
fileSystems.${config.mountpoint} = {
|
||||
device = config.device;
|
||||
@@ -221,11 +270,12 @@ in
|
||||
options = config.mountOptions;
|
||||
};
|
||||
})
|
||||
(map
|
||||
(subvol: swapConfig {
|
||||
(map (
|
||||
subvol:
|
||||
swapConfig {
|
||||
inherit (subvol) mountpoint swap;
|
||||
})
|
||||
(lib.attrValues config.subvolumes))
|
||||
}
|
||||
) (lib.attrValues config.subvolumes))
|
||||
(swapConfig {
|
||||
inherit (config) mountpoint swap;
|
||||
})
|
||||
@@ -236,8 +286,10 @@ in
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||
default = pkgs:
|
||||
[ pkgs.btrfs-progs pkgs.gnugrep ];
|
||||
default = pkgs: [
|
||||
pkgs.btrfs-progs
|
||||
pkgs.gnugrep
|
||||
];
|
||||
description = "Packages";
|
||||
};
|
||||
};
|
||||
|
||||
+22
-6
@@ -1,4 +1,10 @@
|
||||
{ config, options, lib, diskoLib, ... }:
|
||||
{
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
diskoLib,
|
||||
...
|
||||
}:
|
||||
{
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
@@ -32,13 +38,20 @@
|
||||
'';
|
||||
default = "2G";
|
||||
};
|
||||
content = diskoLib.deviceType { parent = config; device = config.device; };
|
||||
content = diskoLib.deviceType {
|
||||
parent = config;
|
||||
device = config.device;
|
||||
};
|
||||
_meta = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = diskoLib.jsonType;
|
||||
default =
|
||||
lib.optionalAttrs (config.content != null) (config.content._meta [ "disk" config.device ]);
|
||||
default = lib.optionalAttrs (config.content != null) (
|
||||
config.content._meta [
|
||||
"disk"
|
||||
config.name
|
||||
]
|
||||
);
|
||||
description = "Metadata";
|
||||
};
|
||||
_create = diskoLib.mkCreateOption {
|
||||
@@ -49,11 +62,14 @@
|
||||
inherit config options;
|
||||
default = lib.optionalAttrs (config.content != null) config.content._mount;
|
||||
};
|
||||
_unmount = diskoLib.mkUnmountOption {
|
||||
inherit config options;
|
||||
default = lib.optionalAttrs (config.content != null) config.content._unmount;
|
||||
};
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default =
|
||||
lib.optional (config.content != null) config.content._config;
|
||||
default = lib.optional (config.content != null) config.content._config;
|
||||
description = "NixOS configuration";
|
||||
};
|
||||
_pkgs = lib.mkOption {
|
||||
|
||||
+47
-13
@@ -1,4 +1,13 @@
|
||||
{ config, options, lib, diskoLib, rootMountPoint, parent, device, ... }:
|
||||
{
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
diskoLib,
|
||||
rootMountPoint,
|
||||
parent,
|
||||
device,
|
||||
...
|
||||
}:
|
||||
{
|
||||
options = {
|
||||
type = lib.mkOption {
|
||||
@@ -64,6 +73,16 @@
|
||||
'';
|
||||
};
|
||||
};
|
||||
_unmount = diskoLib.mkUnmountOption {
|
||||
inherit config options;
|
||||
default = lib.optionalAttrs (config.mountpoint != null) {
|
||||
fs.${config.mountpoint} = ''
|
||||
if findmnt "${config.device}" "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
|
||||
umount "${rootMountPoint}${config.mountpoint}"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
};
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
@@ -80,18 +99,33 @@
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
# type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||
default = pkgs:
|
||||
[ pkgs.util-linux pkgs.gnugrep ] ++ (
|
||||
# TODO add many more
|
||||
if (config.format == "xfs") then [ pkgs.xfsprogs ]
|
||||
else if (config.format == "btrfs") then [ pkgs.btrfs-progs ]
|
||||
else if (config.format == "vfat") then [ pkgs.dosfstools ]
|
||||
else if (config.format == "ext2") then [ pkgs.e2fsprogs ]
|
||||
else if (config.format == "ext3") then [ pkgs.e2fsprogs ]
|
||||
else if (config.format == "ext4") then [ pkgs.e2fsprogs ]
|
||||
else if (config.format == "bcachefs") then [ pkgs.bcachefs-tools ]
|
||||
else if (config.format == "f2fs") then [ pkgs.f2fs-tools ]
|
||||
else [ ]
|
||||
default =
|
||||
pkgs:
|
||||
[
|
||||
pkgs.util-linux
|
||||
pkgs.gnugrep
|
||||
]
|
||||
++ (
|
||||
if (config.format == "xfs") then
|
||||
[ pkgs.xfsprogs ]
|
||||
else if (config.format == "btrfs") then
|
||||
[ pkgs.btrfs-progs ]
|
||||
else if (config.format == "vfat") then
|
||||
[ pkgs.dosfstools ]
|
||||
else if (config.format == "ext2") then
|
||||
[ pkgs.e2fsprogs ]
|
||||
else if (config.format == "ext3") then
|
||||
[ pkgs.e2fsprogs ]
|
||||
else if (config.format == "ext4") then
|
||||
[ pkgs.e2fsprogs ]
|
||||
else if (config.format == "bcachefs") then
|
||||
[ pkgs.bcachefs-tools ]
|
||||
else if (config.format == "f2fs") then
|
||||
[ pkgs.f2fs-tools ]
|
||||
else if (config.format == "exfat") then
|
||||
[ pkgs.exfatprogs ]
|
||||
else
|
||||
[ ]
|
||||
);
|
||||
description = "Packages";
|
||||
};
|
||||
|
||||
+165
-58
@@ -1,4 +1,12 @@
|
||||
{ config, options, lib, diskoLib, parent, device, ... }:
|
||||
{
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
diskoLib,
|
||||
parent,
|
||||
device,
|
||||
...
|
||||
}:
|
||||
let
|
||||
sortedPartitions = lib.sort (x: y: x.priority < y.priority) (lib.attrValues config.partitions);
|
||||
sortedHybridPartitions = lib.filter (p: p.hybrid != null) sortedPartitions;
|
||||
@@ -16,17 +24,32 @@ in
|
||||
description = "Device to use for the partition table";
|
||||
};
|
||||
partitions = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule ({ name, ... }@partition: {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule (
|
||||
{ name, ... }@partition:
|
||||
{
|
||||
options = {
|
||||
type = lib.mkOption {
|
||||
type =
|
||||
let
|
||||
hexPattern = len: "[A-Fa-f0-9]{${toString len}}";
|
||||
in
|
||||
lib.types.either
|
||||
(lib.types.strMatching (hexPattern 4))
|
||||
(lib.types.strMatching (lib.concatMapStringsSep "-" hexPattern [ 8 4 4 4 12 ]));
|
||||
default = if partition.config.content.type == "swap" then "8200" else "8300";
|
||||
lib.types.either (lib.types.strMatching (hexPattern 4)) (
|
||||
lib.types.strMatching (
|
||||
lib.concatMapStringsSep "-" hexPattern [
|
||||
8
|
||||
4
|
||||
4
|
||||
4
|
||||
12
|
||||
]
|
||||
)
|
||||
);
|
||||
default =
|
||||
if partition.config.content != null && partition.config.content.type == "swap" then
|
||||
"8200"
|
||||
else
|
||||
"8300";
|
||||
defaultText = ''8300 (Linux filesystem) normally, 8200 (Linux swap) if content.type is "swap"'';
|
||||
description = ''
|
||||
Filesystem type to use.
|
||||
@@ -37,11 +60,23 @@ in
|
||||
device = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default =
|
||||
if config._parent.type == "mdadm" then
|
||||
if partition.config.uuid != null then
|
||||
"/dev/disk/by-partuuid/${partition.config.uuid}"
|
||||
else if config._parent.type == "mdadm" then
|
||||
# workaround because mdadm partlabel do not appear in /dev/disk/by-partlabel
|
||||
"/dev/disk/by-id/md-name-any:${config._parent.name}-part${toString partition.config._index}"
|
||||
else
|
||||
"/dev/disk/by-partlabel/${diskoLib.hexEscapeUdevSymlink partition.config.label}";
|
||||
defaultText = ''
|
||||
if `uuid` is provided:
|
||||
/dev/disk/by-partuuid/''${partition.config.uuid}
|
||||
|
||||
otherwise, if the parent is an mdadm device:
|
||||
/dev/disk/by-id/md-name-any:''${config._parent.name}-part''${toString partition.config._index}
|
||||
|
||||
otherwise:
|
||||
/dev/disk/by-partlabel/''${diskoLib.hexEscapeUdevSymlink partition.config.label}
|
||||
'';
|
||||
description = "Device to use for the partition";
|
||||
};
|
||||
priority = lib.mkOption {
|
||||
@@ -67,6 +102,19 @@ in
|
||||
description = "Name of the partition";
|
||||
default = name;
|
||||
};
|
||||
uuid = lib.mkOption {
|
||||
type = lib.types.nullOr (
|
||||
lib.types.strMatching "[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}"
|
||||
);
|
||||
default = null;
|
||||
defaultText = "`null` - generate a UUID when creating the partition";
|
||||
example = "809b3a2b-828a-4730-95e1-75b6343e415a";
|
||||
description = ''
|
||||
The UUID (also known as GUID) of the partition. Note that this is distinct from the UUID of the filesystem.
|
||||
|
||||
You can generate a UUID with the command `uuidgen -r`.
|
||||
'';
|
||||
};
|
||||
label = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default =
|
||||
@@ -80,6 +128,11 @@ in
|
||||
builtins.substring 0 limit (builtins.hashString "sha256" label)
|
||||
else
|
||||
label;
|
||||
defaultText = ''
|
||||
''${config._parent.type}-''${config._parent.name}-''${partition.config.name}
|
||||
|
||||
or a truncated hash of the above if it is longer than 36 characters
|
||||
'';
|
||||
};
|
||||
size = lib.mkOption {
|
||||
type = lib.types.either (lib.types.enum [ "100%" ]) (lib.types.strMatching "[0-9]+[KMGTP]?");
|
||||
@@ -92,7 +145,20 @@ in
|
||||
};
|
||||
alignment = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = if (builtins.substring (builtins.stringLength partition.config.start - 1) 1 partition.config.start == "s" || (builtins.substring (builtins.stringLength partition.config.end - 1) 1 partition.config.end == "s")) then 1 else 0;
|
||||
default =
|
||||
if
|
||||
(
|
||||
builtins.substring (builtins.stringLength partition.config.start - 1) 1 partition.config.start
|
||||
== "s"
|
||||
|| (
|
||||
builtins.substring (builtins.stringLength partition.config.end - 1) 1 partition.config.end == "s"
|
||||
)
|
||||
)
|
||||
then
|
||||
1
|
||||
else
|
||||
0;
|
||||
defaultText = "1 if the unit of start or end is sectors, 0 otherwise";
|
||||
description = "Alignment of the partition, if sectors are used as start or end it can be aligned to 1";
|
||||
};
|
||||
start = lib.mkOption {
|
||||
@@ -103,15 +169,24 @@ in
|
||||
end = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = if partition.config.size == "100%" then "-0" else "+${partition.config.size}";
|
||||
defaultText = ''
|
||||
if partition.config.size == "100%" then "-0" else "+''${partition.config.size}";
|
||||
'';
|
||||
description = ''
|
||||
End of the partition, in sgdisk format.
|
||||
Use + for relative sizes from the partitions start
|
||||
or - for relative sizes from the disks end
|
||||
'';
|
||||
};
|
||||
content = diskoLib.partitionType { parent = config; device = partition.config.device; };
|
||||
content = diskoLib.partitionType {
|
||||
parent = config;
|
||||
device = partition.config.device;
|
||||
};
|
||||
hybrid = lib.mkOption {
|
||||
type = lib.types.nullOr (lib.types.submodule ({ ... } @ hp: {
|
||||
type = lib.types.nullOr (
|
||||
lib.types.submodule (
|
||||
{ ... }@hp:
|
||||
{
|
||||
options = {
|
||||
mbrPartitionType = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
@@ -137,16 +212,22 @@ in
|
||||
'';
|
||||
};
|
||||
};
|
||||
}));
|
||||
}
|
||||
)
|
||||
);
|
||||
default = null;
|
||||
description = "Entry to add to the Hybrid MBR table";
|
||||
};
|
||||
_index = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
internal = true;
|
||||
default = diskoLib.indexOf (x: x.name == partition.config.name) sortedPartitions 0;
|
||||
defaultText = null;
|
||||
};
|
||||
};
|
||||
}));
|
||||
}
|
||||
)
|
||||
);
|
||||
default = { };
|
||||
description = "Attrs of partitions to add to the partition table";
|
||||
};
|
||||
@@ -163,12 +244,13 @@ in
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = lib.types.functionTo diskoLib.jsonType;
|
||||
default = dev:
|
||||
lib.foldr lib.recursiveUpdate { } (map
|
||||
(partition:
|
||||
lib.optionalAttrs (partition.content != null) (partition.content._meta dev)
|
||||
default =
|
||||
dev:
|
||||
lib.foldr lib.recursiveUpdate { } (
|
||||
map (partition: lib.optionalAttrs (partition.content != null) (partition.content._meta dev)) (
|
||||
lib.attrValues config.partitions
|
||||
)
|
||||
(lib.attrValues config.partitions));
|
||||
);
|
||||
description = "Metadata";
|
||||
};
|
||||
_create = diskoLib.mkCreateOption {
|
||||
@@ -177,54 +259,78 @@ in
|
||||
if ! blkid "${config.device}" >&2; then
|
||||
sgdisk --clear "${config.device}"
|
||||
fi
|
||||
${lib.concatStrings (map (partition: ''
|
||||
# try to create the partition, if it fails, try to change the type and name
|
||||
if ! sgdisk \
|
||||
--align-end ${lib.optionalString (partition.alignment != 0) ''--set-alignment=${builtins.toString partition.alignment}''} \
|
||||
${lib.concatMapStrings (
|
||||
partition:
|
||||
let
|
||||
args = ''
|
||||
--partition-guid="${toString partition._index}:${
|
||||
if partition.uuid == null then "R" else partition.uuid
|
||||
}" \
|
||||
--change-name="${toString partition._index}:${partition.label}" \
|
||||
--typecode=${toString partition._index}:${partition.type} \
|
||||
"${config.device}" \
|
||||
'';
|
||||
createArgs = ''
|
||||
--align-end ${
|
||||
lib.optionalString (
|
||||
partition.alignment != 0
|
||||
) ''--set-alignment=${builtins.toString partition.alignment}''
|
||||
} \
|
||||
--new=${toString partition._index}:${partition.start}:${partition.end} \
|
||||
--change-name="${toString partition._index}:${partition.label}" \
|
||||
--typecode=${toString partition._index}:${partition.type} \
|
||||
"${config.device}"
|
||||
then sgdisk \
|
||||
--change-name="${toString partition._index}:${partition.label}" \
|
||||
--typecode=${toString partition._index}:${partition.type} \
|
||||
"${config.device}"
|
||||
'';
|
||||
in
|
||||
''
|
||||
# try to create the partition, if it fails, try to change the type and name
|
||||
if ! sgdisk ${createArgs} ${args}
|
||||
then
|
||||
sgdisk ${args}
|
||||
fi
|
||||
# ensure /dev/disk/by-path/..-partN exists before continuing
|
||||
partprobe "${config.device}" || : # sometimes partprobe fails, but the partitions are still up2date
|
||||
udevadm trigger --subsystem-match=block
|
||||
udevadm settle
|
||||
'') sortedPartitions)}
|
||||
''
|
||||
) sortedPartitions}
|
||||
|
||||
${
|
||||
lib.optionalString (sortedHybridPartitions != [])
|
||||
("sgdisk -h "
|
||||
${lib.optionalString (sortedHybridPartitions != [ ]) (
|
||||
"sgdisk -h "
|
||||
+ (lib.concatStringsSep ":" (map (p: (toString p._index)) sortedHybridPartitions))
|
||||
+ (
|
||||
lib.optionalString (!config.efiGptPartitionFirst) ":EE "
|
||||
)
|
||||
+ ''"${parent.device}"'')
|
||||
}
|
||||
${lib.concatMapStrings (p:
|
||||
p.hybrid._create
|
||||
)
|
||||
sortedHybridPartitions
|
||||
}
|
||||
+ (lib.optionalString (!config.efiGptPartitionFirst) ":EE ")
|
||||
+ ''"${parent.device}"''
|
||||
)}
|
||||
${lib.concatMapStrings (p: p.hybrid._create) sortedHybridPartitions}
|
||||
|
||||
${lib.concatStrings (map (partition: ''
|
||||
${lib.concatStrings (
|
||||
map (partition: ''
|
||||
${lib.optionalString (partition.content != null) partition.content._create}
|
||||
'') sortedPartitions)}
|
||||
'') sortedPartitions
|
||||
)}
|
||||
'';
|
||||
};
|
||||
_mount = diskoLib.mkMountOption {
|
||||
inherit config options;
|
||||
default =
|
||||
let
|
||||
partMounts = lib.foldr lib.recursiveUpdate { } (map
|
||||
(partition:
|
||||
lib.optionalAttrs (partition.content != null) partition.content._mount
|
||||
partMounts = lib.foldr lib.recursiveUpdate { } (
|
||||
map (partition: lib.optionalAttrs (partition.content != null) partition.content._mount) (
|
||||
lib.attrValues config.partitions
|
||||
)
|
||||
(lib.attrValues config.partitions));
|
||||
);
|
||||
in
|
||||
{
|
||||
dev = partMounts.dev or "";
|
||||
fs = partMounts.fs or { };
|
||||
};
|
||||
};
|
||||
_unmount = diskoLib.mkUnmountOption {
|
||||
inherit config options;
|
||||
default =
|
||||
let
|
||||
partMounts = lib.foldr lib.recursiveUpdate { } (
|
||||
map (partition: lib.optionalAttrs (partition.content != null) partition.content._unmount) (
|
||||
lib.attrValues config.partitions
|
||||
)
|
||||
);
|
||||
in
|
||||
{
|
||||
dev = partMounts.dev or "";
|
||||
@@ -234,11 +340,10 @@ in
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = (map
|
||||
(partition:
|
||||
lib.optional (partition.content != null) partition.content._config
|
||||
)
|
||||
(lib.attrValues config.partitions))
|
||||
default =
|
||||
(map (partition: lib.optional (partition.content != null) partition.content._config) (
|
||||
lib.attrValues config.partitions
|
||||
))
|
||||
++ (lib.optional (lib.any (part: part.type == "EF02") (lib.attrValues config.partitions)) {
|
||||
boot.loader.grub.devices = [ config.device ];
|
||||
});
|
||||
@@ -248,16 +353,18 @@ in
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||
default = pkgs:
|
||||
default =
|
||||
pkgs:
|
||||
[
|
||||
pkgs.gptfdisk
|
||||
pkgs.systemdMinimal
|
||||
pkgs.parted # for partprobe
|
||||
] ++ lib.flatten (map
|
||||
(partition:
|
||||
lib.optional (partition.content != null) (partition.content._pkgs pkgs)
|
||||
]
|
||||
++ lib.flatten (
|
||||
map (partition: lib.optional (partition.content != null) (partition.content._pkgs pkgs)) (
|
||||
lib.attrValues config.partitions
|
||||
)
|
||||
(lib.attrValues config.partitions));
|
||||
);
|
||||
description = "Packages";
|
||||
};
|
||||
};
|
||||
|
||||
+66
-23
@@ -1,20 +1,30 @@
|
||||
{ config, options, lib, diskoLib, parent, device, ... }:
|
||||
{
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
diskoLib,
|
||||
parent,
|
||||
device,
|
||||
...
|
||||
}:
|
||||
let
|
||||
keyFile =
|
||||
if config.settings ? "keyFile"
|
||||
then config.settings.keyFile
|
||||
else if config.askPassword
|
||||
then ''<(set +x; echo -n "$password"; set -x)''
|
||||
else if config.passwordFile != null
|
||||
if config.settings ? "keyFile" then
|
||||
config.settings.keyFile
|
||||
else if config.askPassword then
|
||||
''<(set +x; echo -n "$password"; set -x)''
|
||||
else if
|
||||
config.passwordFile != null
|
||||
# do not print the password to the console
|
||||
then ''<(set +x; echo -n "$(cat ${config.passwordFile})"; set -x)''
|
||||
else if config.keyFile != null
|
||||
then
|
||||
lib.warn
|
||||
("The option `keyFile` is deprecated."
|
||||
+ "Use passwordFile instead if you want to use interactive login or settings.keyFile if you want to use key file login")
|
||||
config.keyFile
|
||||
else null;
|
||||
''<(set +x; echo -n "$(cat ${config.passwordFile})"; set -x)''
|
||||
else if config.keyFile != null then
|
||||
lib.warn (
|
||||
"The option `keyFile` is deprecated."
|
||||
+ "Use passwordFile instead if you want to use interactive login or settings.keyFile if you want to use key file login"
|
||||
) config.keyFile
|
||||
else
|
||||
null;
|
||||
keyFileArgs = ''
|
||||
${lib.optionalString (keyFile != null) "--key-file ${keyFile}"} \
|
||||
${lib.optionalString (lib.hasAttr "keyFileSize" config.settings) "--keyfile-size ${builtins.toString config.settings.keyFileSize}"} \
|
||||
@@ -23,7 +33,10 @@ let
|
||||
cryptsetupOpen = ''
|
||||
cryptsetup open "${config.device}" "${config.name}" \
|
||||
${lib.optionalString (config.settings.allowDiscards or false) "--allow-discards"} \
|
||||
${lib.optionalString (config.settings.bypassWorkqueues or false) "--perf-no_read_workqueue --perf-no_write_workqueue"} \
|
||||
${
|
||||
lib.optionalString (config.settings.bypassWorkqueues or false
|
||||
) "--perf-no_read_workqueue --perf-no_write_workqueue"
|
||||
} \
|
||||
${toString config.extraOpenArgs} \
|
||||
${keyFileArgs} \
|
||||
'';
|
||||
@@ -59,12 +72,15 @@ in
|
||||
askPassword = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = config.keyFile == null && config.passwordFile == null && (!config.settings ? "keyFile");
|
||||
defaultText = "true if neither keyFile nor passwordFile are set";
|
||||
description = "Whether to ask for a password for initial encryption";
|
||||
};
|
||||
settings = lib.mkOption {
|
||||
type = lib.types.attrsOf lib.types.anything;
|
||||
default = { };
|
||||
description = "LUKS settings (as defined in configuration.nix in boot.initrd.luks.devices.<name>)";
|
||||
example = ''{
|
||||
example = ''
|
||||
{
|
||||
keyFile = "/tmp/disk.key";
|
||||
keyFileSize = 2048;
|
||||
keyFileOffset = 1024;
|
||||
@@ -96,7 +112,10 @@ in
|
||||
description = "Extra arguments to pass to `cryptsetup luksOpen` when opening";
|
||||
example = [ "--timeout 10" ];
|
||||
};
|
||||
content = diskoLib.deviceType { parent = config; device = "/dev/mapper/${config.name}"; };
|
||||
content = diskoLib.deviceType {
|
||||
parent = config;
|
||||
device = "/dev/mapper/${config.name}";
|
||||
};
|
||||
_parent = lib.mkOption {
|
||||
internal = true;
|
||||
default = parent;
|
||||
@@ -105,8 +124,7 @@ in
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = lib.types.functionTo diskoLib.jsonType;
|
||||
default = dev:
|
||||
lib.optionalAttrs (config.content != null) (config.content._meta dev);
|
||||
default = dev: lib.optionalAttrs (config.content != null) (config.content._meta dev);
|
||||
description = "Metadata";
|
||||
};
|
||||
_create = diskoLib.mkCreateOption {
|
||||
@@ -134,9 +152,11 @@ in
|
||||
''}
|
||||
cryptsetup -q luksFormat "${config.device}" ${toString config.extraFormatArgs} ${keyFileArgs}
|
||||
${cryptsetupOpen} --persistent
|
||||
${toString (lib.forEach config.additionalKeyFiles (keyFile: ''
|
||||
${toString (
|
||||
lib.forEach config.additionalKeyFiles (keyFile: ''
|
||||
cryptsetup luksAddKey "${config.device}" ${keyFile} ${keyFileArgs}
|
||||
''))}
|
||||
'')
|
||||
)}
|
||||
fi
|
||||
${lib.optionalString (config.content != null) config.content._create}
|
||||
'';
|
||||
@@ -168,10 +188,26 @@ in
|
||||
fs = lib.optionalAttrs (config.content != null) contentMount.fs or { };
|
||||
};
|
||||
};
|
||||
_unmount = diskoLib.mkUnmountOption {
|
||||
inherit config options;
|
||||
default =
|
||||
let
|
||||
contentUnmount = config.content._unmount;
|
||||
in
|
||||
{
|
||||
dev = ''
|
||||
${lib.optionalString (config.content != null) contentUnmount.dev or ""}
|
||||
if cryptsetup status "${config.name}" >/dev/null 2>/dev/null; then
|
||||
cryptsetup close "${config.name}"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
};
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = [ ]
|
||||
default =
|
||||
[ ]
|
||||
# If initrdUnlock is true, then add a device entry to the initrd.luks.devices config.
|
||||
++ (lib.optional config.initrdUnlock [
|
||||
{
|
||||
@@ -179,14 +215,21 @@ in
|
||||
inherit (config) device;
|
||||
} // config.settings;
|
||||
}
|
||||
]) ++ (lib.optional (config.content != null) config.content._config);
|
||||
])
|
||||
++ (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: [ pkgs.gnugrep pkgs.cryptsetup ] ++ (lib.optionals (config.content != null) (config.content._pkgs pkgs));
|
||||
default =
|
||||
pkgs:
|
||||
[
|
||||
pkgs.gnugrep
|
||||
pkgs.cryptsetup
|
||||
]
|
||||
++ (lib.optionals (config.content != null) (config.content._pkgs pkgs));
|
||||
description = "Packages";
|
||||
};
|
||||
};
|
||||
|
||||
+17
-2
@@ -1,4 +1,12 @@
|
||||
{ config, options, lib, diskoLib, parent, device, ... }:
|
||||
{
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
diskoLib,
|
||||
parent,
|
||||
device,
|
||||
...
|
||||
}:
|
||||
{
|
||||
options = {
|
||||
type = lib.mkOption {
|
||||
@@ -41,6 +49,10 @@
|
||||
inherit config options;
|
||||
default = { };
|
||||
};
|
||||
_unmount = diskoLib.mkUnmountOption {
|
||||
inherit config options;
|
||||
default = { };
|
||||
};
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
@@ -51,7 +63,10 @@
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||
default = pkgs: [ pkgs.gnugrep pkgs.lvm2 ];
|
||||
default = pkgs: [
|
||||
pkgs.gnugrep
|
||||
pkgs.lvm2
|
||||
];
|
||||
description = "Packages";
|
||||
};
|
||||
};
|
||||
|
||||
+88
-37
@@ -1,14 +1,22 @@
|
||||
{ config, options, lib, diskoLib, ... }:
|
||||
{
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
diskoLib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
# Load kernel modules to ensure device mapper types are available
|
||||
kernelModules =
|
||||
[
|
||||
# Prevent unbootable systems if LVM snapshots are present at boot time.
|
||||
"dm-snapshot"
|
||||
] ++
|
||||
lib.filter (x: x != "") (map
|
||||
(lv: lib.optionalString (lv.lvm_type != null && lv.lvm_type != "thinlv") "dm-${lv.lvm_type}")
|
||||
(lib.attrValues config.lvs));
|
||||
]
|
||||
++ lib.filter (x: x != "") (
|
||||
map (lv: lib.optionalString (lv.lvm_type != null && lv.lvm_type != "thinlv") "dm-${lv.lvm_type}") (
|
||||
lib.attrValues config.lvs
|
||||
)
|
||||
);
|
||||
in
|
||||
{
|
||||
options = {
|
||||
@@ -23,7 +31,10 @@ in
|
||||
description = "Type";
|
||||
};
|
||||
lvs = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.submodule ({ name, ... }@lv: {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule (
|
||||
{ name, ... }@lv:
|
||||
{
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
@@ -32,7 +43,9 @@ in
|
||||
};
|
||||
priority = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = (if lv.config.lvm_type == "thin-pool" then 501 else 1000) + (if lib.hasInfix "100%" lv.config.size then 251 else 0);
|
||||
default =
|
||||
(if lv.config.lvm_type == "thin-pool" then 501 else 1000)
|
||||
+ (if lib.hasInfix "100%" lv.config.size then 251 else 0);
|
||||
defaultText = lib.literalExpression ''
|
||||
if (lib.hasInfix "100%" lv.config.size) then 9001 else 1000
|
||||
'';
|
||||
@@ -44,7 +57,18 @@ in
|
||||
};
|
||||
lvm_type = lib.mkOption {
|
||||
# TODO: add raid10
|
||||
type = lib.types.nullOr (lib.types.enum [ "mirror" "raid0" "raid1" "raid4" "raid5" "raid6" "thin-pool" "thinlv" ]); # TODO add all lib.types
|
||||
type = lib.types.nullOr (
|
||||
lib.types.enum [
|
||||
"mirror"
|
||||
"raid0"
|
||||
"raid1"
|
||||
"raid4"
|
||||
"raid5"
|
||||
"raid6"
|
||||
"thin-pool"
|
||||
"thinlv"
|
||||
]
|
||||
); # TODO add all lib.types
|
||||
default = null; # maybe there is always a default type?
|
||||
description = "LVM type";
|
||||
};
|
||||
@@ -58,9 +82,14 @@ in
|
||||
default = null;
|
||||
description = "Name of pool LV that this LV belongs to";
|
||||
};
|
||||
content = diskoLib.partitionType { parent = config; device = "/dev/${config.name}/${lv.config.name}"; };
|
||||
content = diskoLib.partitionType {
|
||||
parent = config;
|
||||
device = "/dev/${config.name}/${lv.config.name}";
|
||||
};
|
||||
}));
|
||||
};
|
||||
}
|
||||
)
|
||||
);
|
||||
default = { };
|
||||
description = "LVS for the volume group";
|
||||
};
|
||||
@@ -68,12 +97,15 @@ in
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = diskoLib.jsonType;
|
||||
default =
|
||||
diskoLib.deepMergeMap
|
||||
(lv:
|
||||
lib.optionalAttrs (lv.content != null) (lv.content._meta [ "lvm_vg" config.name ])
|
||||
default = diskoLib.deepMergeMap (
|
||||
lv:
|
||||
lib.optionalAttrs (lv.content != null) (
|
||||
lv.content._meta [
|
||||
"lvm_vg"
|
||||
config.name
|
||||
]
|
||||
)
|
||||
(lib.attrValues config.lvs);
|
||||
) (lib.attrValues config.lvs);
|
||||
description = "Metadata";
|
||||
};
|
||||
_create = diskoLib.mkCreateOption {
|
||||
@@ -93,8 +125,14 @@ in
|
||||
if ! lvdisplay "${config.name}/${lv.name}"; then
|
||||
lvcreate \
|
||||
--yes \
|
||||
${if (lv.lvm_type == "thinlv") then "-V"
|
||||
else if lib.hasInfix "%" lv.size then "-l" else "-L"} \
|
||||
${
|
||||
if (lv.lvm_type == "thinlv") then
|
||||
"-V"
|
||||
else if lib.hasInfix "%" lv.size then
|
||||
"-l"
|
||||
else
|
||||
"-L"
|
||||
} \
|
||||
${if lib.hasSuffix "%" lv.size then "${lv.size}FREE" else lv.size} \
|
||||
-n "${lv.name}" \
|
||||
${lib.optionalString (lv.lvm_type == "thinlv") "--thinpool=${lv.pool}"} \
|
||||
@@ -113,11 +151,9 @@ in
|
||||
inherit config options;
|
||||
default =
|
||||
let
|
||||
lvMounts = diskoLib.deepMergeMap
|
||||
(lv:
|
||||
lib.optionalAttrs (lv.content != null) lv.content._mount
|
||||
)
|
||||
(lib.attrValues config.lvs);
|
||||
lvMounts = diskoLib.deepMergeMap (lv: lib.optionalAttrs (lv.content != null) lv.content._mount) (
|
||||
lib.attrValues config.lvs
|
||||
);
|
||||
in
|
||||
{
|
||||
dev = ''
|
||||
@@ -127,39 +163,54 @@ in
|
||||
fs = lvMounts.fs or { };
|
||||
};
|
||||
};
|
||||
_unmount = diskoLib.mkUnmountOption {
|
||||
inherit config options;
|
||||
default =
|
||||
let
|
||||
lvMounts = diskoLib.deepMergeMap (lv: lib.optionalAttrs (lv.content != null) lv.content._unmount) (
|
||||
lib.attrValues config.lvs
|
||||
);
|
||||
in
|
||||
{
|
||||
dev = ''
|
||||
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues lvMounts)}
|
||||
vgchange -a n
|
||||
'';
|
||||
fs = lvMounts.fs or { };
|
||||
};
|
||||
};
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = [{ boot.initrd.kernelModules = kernelModules; }] ++
|
||||
map
|
||||
(lv: [
|
||||
default =
|
||||
[ { boot.initrd.kernelModules = kernelModules; } ]
|
||||
++ map (lv: [
|
||||
(lib.optional (lv.content != null) lv.content._config)
|
||||
(lib.optional (lv.lvm_type != null) {
|
||||
boot.initrd.kernelModules = [
|
||||
boot.initrd.kernelModules =
|
||||
[
|
||||
(if lv.lvm_type == "mirror" then "dm-mirror" else "dm-raid")
|
||||
]
|
||||
++ lib.optional (lv.lvm_type == "raid0") "raid0"
|
||||
++ lib.optional (lv.lvm_type == "raid1") "raid1"
|
||||
# ++ lib.optional (lv.lvm_type == "raid10") "raid10"
|
||||
++ lib.optional
|
||||
(lv.lvm_type == "raid4" ||
|
||||
lv.lvm_type == "raid5" ||
|
||||
lv.lvm_type == "raid6") "raid456";
|
||||
++ lib.optional (
|
||||
lv.lvm_type == "raid4" || lv.lvm_type == "raid5" || lv.lvm_type == "raid6"
|
||||
) "raid456";
|
||||
|
||||
})
|
||||
])
|
||||
(lib.attrValues config.lvs);
|
||||
]) (lib.attrValues config.lvs);
|
||||
description = "NixOS configuration";
|
||||
};
|
||||
_pkgs = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||
default = pkgs: lib.flatten (map
|
||||
(lv:
|
||||
lib.optional (lv.content != null) (lv.content._pkgs pkgs)
|
||||
)
|
||||
(lib.attrValues config.lvs));
|
||||
default =
|
||||
pkgs:
|
||||
lib.flatten (
|
||||
map (lv: lib.optional (lv.content != null) (lv.content._pkgs pkgs)) (lib.attrValues config.lvs)
|
||||
);
|
||||
description = "Packages";
|
||||
};
|
||||
};
|
||||
|
||||
+58
-16
@@ -1,4 +1,10 @@
|
||||
{ config, options, lib, diskoLib, ... }:
|
||||
{
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
diskoLib,
|
||||
...
|
||||
}:
|
||||
{
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
@@ -18,17 +24,32 @@
|
||||
description = "mdadm level";
|
||||
};
|
||||
metadata = lib.mkOption {
|
||||
type = lib.types.enum [ "1" "1.0" "1.1" "1.2" "default" "ddf" "imsm" ];
|
||||
type = lib.types.enum [
|
||||
"1"
|
||||
"1.0"
|
||||
"1.1"
|
||||
"1.2"
|
||||
"default"
|
||||
"ddf"
|
||||
"imsm"
|
||||
];
|
||||
default = "default";
|
||||
description = "Metadata";
|
||||
};
|
||||
content = diskoLib.deviceType { parent = config; device = "/dev/md/${config.name}"; };
|
||||
content = diskoLib.deviceType {
|
||||
parent = config;
|
||||
device = "/dev/md/${config.name}";
|
||||
};
|
||||
_meta = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = diskoLib.jsonType;
|
||||
default =
|
||||
lib.optionalAttrs (config.content != null) (config.content._meta [ "mdadm" config.name ]);
|
||||
default = lib.optionalAttrs (config.content != null) (
|
||||
config.content._meta [
|
||||
"mdadm"
|
||||
config.name
|
||||
]
|
||||
);
|
||||
description = "Metadata";
|
||||
};
|
||||
_create = diskoLib.mkCreateOption {
|
||||
@@ -54,31 +75,52 @@
|
||||
};
|
||||
_mount = diskoLib.mkMountOption {
|
||||
inherit config options;
|
||||
default =
|
||||
lib.optionalAttrs (config.content != null) config.content._mount;
|
||||
default = lib.optionalAttrs (config.content != null) config.content._mount;
|
||||
# TODO we probably need to assemble the mdadm somehow
|
||||
};
|
||||
_unmount = diskoLib.mkUnmountOption {
|
||||
inherit config options;
|
||||
default =
|
||||
let
|
||||
content = lib.optionalAttrs (config.content != null) config.content._unmount;
|
||||
in
|
||||
{
|
||||
fs = content.fs;
|
||||
dev = ''
|
||||
${content.dev or ""}
|
||||
if [ -e "/dev/md/${config.name}" ]; then
|
||||
mdadm --stop "/dev/md/${config.name}"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
};
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default =
|
||||
[
|
||||
(if lib.versionAtLeast (lib.versions.majorMinor lib.version) "23.11" then {
|
||||
default = [
|
||||
(
|
||||
if lib.versionAtLeast (lib.versions.majorMinor lib.version) "23.11" then
|
||||
{
|
||||
boot.swraid.enable = true;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
boot.initrd.services.swraid.enable = true;
|
||||
})
|
||||
] ++
|
||||
lib.optional (config.content != null) config.content._config;
|
||||
}
|
||||
)
|
||||
] ++ 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: [
|
||||
default =
|
||||
pkgs:
|
||||
[
|
||||
pkgs.parted # for partprobe
|
||||
] ++ (lib.optionals (config.content != null) (config.content._pkgs pkgs));
|
||||
]
|
||||
++ (lib.optionals (config.content != null) (config.content._pkgs pkgs));
|
||||
description = "Packages";
|
||||
};
|
||||
};
|
||||
|
||||
+13
-1
@@ -1,4 +1,12 @@
|
||||
{ config, options, lib, diskoLib, parent, device, ... }:
|
||||
{
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
diskoLib,
|
||||
parent,
|
||||
device,
|
||||
...
|
||||
}:
|
||||
{
|
||||
options = {
|
||||
type = lib.mkOption {
|
||||
@@ -39,6 +47,10 @@
|
||||
inherit config options;
|
||||
default = { };
|
||||
};
|
||||
_unmount = diskoLib.mkUnmountOption {
|
||||
inherit config options;
|
||||
default = { };
|
||||
};
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
|
||||
+18
-1
@@ -1,4 +1,11 @@
|
||||
{ lib, config, options, diskoLib, rootMountPoint, ... }:
|
||||
{
|
||||
lib,
|
||||
config,
|
||||
options,
|
||||
diskoLib,
|
||||
rootMountPoint,
|
||||
...
|
||||
}:
|
||||
{
|
||||
options = {
|
||||
type = lib.mkOption {
|
||||
@@ -49,6 +56,16 @@
|
||||
'';
|
||||
};
|
||||
};
|
||||
_unmount = diskoLib.mkUnmountOption {
|
||||
inherit config options;
|
||||
default = lib.optionalAttrs (config.mountpoint != null) {
|
||||
fs.${config.mountpoint} = ''
|
||||
if findmnt ${config.fsType} "${rootMountPoint}${config.mountpoint}" > /dev/null 2>&1; then
|
||||
umount "${rootMountPoint}${config.mountpoint}"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
};
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
|
||||
+43
-16
@@ -1,4 +1,12 @@
|
||||
{ diskoLib, config, options, lib, parent, device, ... }:
|
||||
{
|
||||
diskoLib,
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
parent,
|
||||
device,
|
||||
...
|
||||
}:
|
||||
{
|
||||
options = {
|
||||
type = lib.mkOption {
|
||||
@@ -14,8 +22,14 @@
|
||||
discardPolicy = lib.mkOption {
|
||||
default = null;
|
||||
example = "once";
|
||||
type = lib.types.nullOr (lib.types.enum [ "once" "pages" "both" ]);
|
||||
description = lib.mdDoc ''
|
||||
type = lib.types.nullOr (
|
||||
lib.types.enum [
|
||||
"once"
|
||||
"pages"
|
||||
"both"
|
||||
]
|
||||
);
|
||||
description = ''
|
||||
Specify the discard policy for the swap device. If "once", then the
|
||||
whole swap space is discarded at swapon invocation. If "pages",
|
||||
asynchronous discard on freed pages is performed, before returning to
|
||||
@@ -37,7 +51,7 @@
|
||||
priority = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.int;
|
||||
default = null;
|
||||
description = lib.mdDoc ''
|
||||
description = ''
|
||||
Specify the priority of the swap device. Priority is a value between 0 and 32767.
|
||||
Higher numbers indicate higher priority.
|
||||
null lets the kernel choose a priority, which will show up as a negative value.
|
||||
@@ -80,26 +94,34 @@
|
||||
# TODO: we don't support encrypted swap yet
|
||||
default = lib.optionalAttrs (!config.randomEncryption) {
|
||||
fs.${config.device} = ''
|
||||
if ! swapon --show | grep -q "^$(readlink -f "${config.device}") "; then
|
||||
if test "''${DISKO_SKIP_SWAP:-}" != 1 && ! swapon --show | grep -q "^$(readlink -f "${config.device}") "; then
|
||||
swapon ${
|
||||
lib.optionalString (config.discardPolicy != null)
|
||||
"--discard${lib.optionalString (config.discardPolicy != "both")
|
||||
"=${config.discardPolicy}"
|
||||
}"} ${
|
||||
lib.optionalString (config.priority != null)
|
||||
"--priority=${toString config.priority}"
|
||||
} \
|
||||
"--discard${lib.optionalString (config.discardPolicy != "both") "=${config.discardPolicy}"}"
|
||||
} ${lib.optionalString (config.priority != null) "--priority=${toString config.priority}"} \
|
||||
--options=${lib.concatStringsSep "," config.mountOptions} \
|
||||
"${config.device}"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
};
|
||||
_unmount = diskoLib.mkUnmountOption {
|
||||
inherit config options;
|
||||
default = lib.optionalAttrs (!config.randomEncryption) {
|
||||
fs.${config.device} = ''
|
||||
if swapon --show | grep -q "^$(readlink -f "${config.device}") "; then
|
||||
swapoff "${config.device}"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
};
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default = [{
|
||||
swapDevices = [{
|
||||
default = [
|
||||
{
|
||||
swapDevices = [
|
||||
{
|
||||
device = config.device;
|
||||
inherit (config) discardPolicy priority;
|
||||
randomEncryption = {
|
||||
@@ -108,16 +130,21 @@
|
||||
allowDiscards = config.discardPolicy != null;
|
||||
};
|
||||
options = config.mountOptions;
|
||||
}];
|
||||
}
|
||||
];
|
||||
boot.resumeDevice = lib.mkIf config.resumeDevice config.device;
|
||||
}];
|
||||
}
|
||||
];
|
||||
description = "NixOS configuration";
|
||||
};
|
||||
_pkgs = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||
default = pkgs: [ pkgs.gnugrep pkgs.util-linux ];
|
||||
default = pkgs: [
|
||||
pkgs.gnugrep
|
||||
pkgs.util-linux
|
||||
];
|
||||
description = "Packages";
|
||||
};
|
||||
};
|
||||
|
||||
+100
-35
@@ -1,6 +1,16 @@
|
||||
{ config, options, lib, diskoLib, parent, device, ... }:
|
||||
{
|
||||
options = lib.warn ''
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
diskoLib,
|
||||
parent,
|
||||
device,
|
||||
...
|
||||
}:
|
||||
{
|
||||
options =
|
||||
lib.warn
|
||||
''
|
||||
The legacy table is outdated and should not be used. We recommend using the gpt type instead.
|
||||
Please note that certain features, such as the test framework, may not function properly with the legacy table type.
|
||||
If you encounter errors similar to:
|
||||
@@ -20,20 +30,46 @@
|
||||
description = "Device to partition";
|
||||
};
|
||||
format = lib.mkOption {
|
||||
type = lib.types.enum [ "gpt" "msdos" ];
|
||||
type = lib.types.enum [
|
||||
"gpt"
|
||||
"msdos"
|
||||
];
|
||||
default = "gpt";
|
||||
description = "The kind of partition table";
|
||||
};
|
||||
partitions = lib.mkOption {
|
||||
type = lib.types.listOf (lib.types.submodule ({ name, ... }@partition: {
|
||||
type = lib.types.listOf (
|
||||
lib.types.submodule (
|
||||
{ name, ... }@partition:
|
||||
{
|
||||
options = {
|
||||
part-type = lib.mkOption {
|
||||
type = lib.types.enum [ "primary" "logical" "extended" ];
|
||||
type = lib.types.enum [
|
||||
"primary"
|
||||
"logical"
|
||||
"extended"
|
||||
];
|
||||
default = "primary";
|
||||
description = "Partition type";
|
||||
};
|
||||
fs-type = lib.mkOption {
|
||||
type = lib.types.nullOr (lib.types.enum [ "btrfs" "ext2" "ext3" "ext4" "fat16" "fat32" "hfs" "hfs+" "linux-swap" "ntfs" "reiserfs" "udf" "xfs" ]);
|
||||
type = lib.types.nullOr (
|
||||
lib.types.enum [
|
||||
"btrfs"
|
||||
"ext2"
|
||||
"ext3"
|
||||
"ext4"
|
||||
"fat16"
|
||||
"fat32"
|
||||
"hfs"
|
||||
"hfs+"
|
||||
"linux-swap"
|
||||
"ntfs"
|
||||
"reiserfs"
|
||||
"udf"
|
||||
"xfs"
|
||||
]
|
||||
);
|
||||
default = null;
|
||||
description = "Filesystem type to use";
|
||||
};
|
||||
@@ -61,13 +97,20 @@
|
||||
default = false;
|
||||
description = "Whether to make the partition bootable";
|
||||
};
|
||||
content = diskoLib.partitionType { parent = config; device = diskoLib.deviceNumbering config.device partition.config._index; };
|
||||
content = diskoLib.partitionType {
|
||||
parent = config;
|
||||
device = diskoLib.deviceNumbering config.device partition.config._index;
|
||||
};
|
||||
_index = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
internal = true;
|
||||
default = lib.toInt (lib.head (builtins.match ".*entry ([[:digit:]]+)]" name));
|
||||
defaultText = null;
|
||||
};
|
||||
};
|
||||
}));
|
||||
}
|
||||
)
|
||||
);
|
||||
default = [ ];
|
||||
description = "List of partitions to add to the partition table";
|
||||
};
|
||||
@@ -79,12 +122,13 @@
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = lib.types.functionTo diskoLib.jsonType;
|
||||
default = dev:
|
||||
lib.foldr lib.recursiveUpdate { } (lib.imap
|
||||
(_index: partition:
|
||||
lib.optionalAttrs (partition.content != null) (partition.content._meta dev)
|
||||
)
|
||||
config.partitions);
|
||||
default =
|
||||
dev:
|
||||
lib.foldr lib.recursiveUpdate { } (
|
||||
lib.imap (
|
||||
_index: partition: lib.optionalAttrs (partition.content != null) (partition.content._meta dev)
|
||||
) config.partitions
|
||||
);
|
||||
description = "Metadata";
|
||||
};
|
||||
_create = diskoLib.mkCreateOption {
|
||||
@@ -92,7 +136,8 @@
|
||||
default = ''
|
||||
if ! blkid "${config.device}" >/dev/null; then
|
||||
parted -s "${config.device}" -- mklabel ${config.format}
|
||||
${lib.concatStrings (map (partition: ''
|
||||
${lib.concatStrings (
|
||||
map (partition: ''
|
||||
${lib.optionalString (config.format == "gpt") ''
|
||||
parted -s "${config.device}" -- mkpart "${diskoLib.hexEscapeUdevSymlink partition.name}" ${diskoLib.maybeStr partition.fs-type} ${partition.start} ${partition.end}
|
||||
''}
|
||||
@@ -113,22 +158,40 @@
|
||||
partprobe "${config.device}"
|
||||
udevadm trigger --subsystem-match=block
|
||||
udevadm settle
|
||||
'') config.partitions)}
|
||||
'') config.partitions
|
||||
)}
|
||||
fi
|
||||
${lib.concatStrings (map (partition: ''
|
||||
${lib.concatStrings (
|
||||
map (partition: ''
|
||||
${lib.optionalString (partition.content != null) partition.content._create}
|
||||
'') config.partitions)}
|
||||
'') config.partitions
|
||||
)}
|
||||
'';
|
||||
};
|
||||
_mount = diskoLib.mkMountOption {
|
||||
inherit config options;
|
||||
default =
|
||||
let
|
||||
partMounts = lib.foldr lib.recursiveUpdate { } (map
|
||||
(partition:
|
||||
lib.optionalAttrs (partition.content != null) partition.content._mount
|
||||
)
|
||||
config.partitions);
|
||||
partMounts = lib.foldr lib.recursiveUpdate { } (
|
||||
map (
|
||||
partition: lib.optionalAttrs (partition.content != null) partition.content._mount
|
||||
) config.partitions
|
||||
);
|
||||
in
|
||||
{
|
||||
dev = partMounts.dev or "";
|
||||
fs = partMounts.fs or { };
|
||||
};
|
||||
};
|
||||
_unmount = diskoLib.mkUnmountOption {
|
||||
inherit config options;
|
||||
default =
|
||||
let
|
||||
partMounts = lib.foldr lib.recursiveUpdate { } (
|
||||
map (
|
||||
partition: lib.optionalAttrs (partition.content != null) partition.content._unmount
|
||||
) config.partitions
|
||||
);
|
||||
in
|
||||
{
|
||||
dev = partMounts.dev or "";
|
||||
@@ -138,24 +201,26 @@
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default =
|
||||
map
|
||||
(partition:
|
||||
lib.optional (partition.content != null) partition.content._config
|
||||
)
|
||||
config.partitions;
|
||||
default = map (
|
||||
partition: lib.optional (partition.content != null) partition.content._config
|
||||
) config.partitions;
|
||||
description = "NixOS configuration";
|
||||
};
|
||||
_pkgs = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||
default = pkgs:
|
||||
[ pkgs.parted pkgs.systemdMinimal ] ++ lib.flatten (map
|
||||
(partition:
|
||||
lib.optional (partition.content != null) (partition.content._pkgs pkgs)
|
||||
)
|
||||
config.partitions);
|
||||
default =
|
||||
pkgs:
|
||||
[
|
||||
pkgs.parted
|
||||
pkgs.systemdMinimal
|
||||
]
|
||||
++ lib.flatten (
|
||||
map (
|
||||
partition: lib.optional (partition.content != null) (partition.content._pkgs pkgs)
|
||||
) config.partitions
|
||||
);
|
||||
description = "Packages";
|
||||
};
|
||||
};
|
||||
|
||||
+13
-1
@@ -1,4 +1,12 @@
|
||||
{ config, options, lib, diskoLib, parent, device, ... }:
|
||||
{
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
diskoLib,
|
||||
parent,
|
||||
device,
|
||||
...
|
||||
}:
|
||||
{
|
||||
options = {
|
||||
type = lib.mkOption {
|
||||
@@ -38,6 +46,10 @@
|
||||
inherit config options;
|
||||
default = { };
|
||||
};
|
||||
_unmount = diskoLib.mkUnmountOption {
|
||||
inherit config options;
|
||||
default = { };
|
||||
};
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
|
||||
+56
-12
@@ -1,4 +1,12 @@
|
||||
{ config, options, lib, diskoLib, rootMountPoint, parent, ... }:
|
||||
{
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
diskoLib,
|
||||
rootMountPoint,
|
||||
parent,
|
||||
...
|
||||
}:
|
||||
{
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
@@ -58,8 +66,7 @@
|
||||
default = true;
|
||||
};
|
||||
|
||||
_create = diskoLib.mkCreateOption
|
||||
{
|
||||
_create = diskoLib.mkCreateOption {
|
||||
inherit config options;
|
||||
# -u prevents mounting newly created datasets, which is
|
||||
# important to prevent accidental shadowing of mount points
|
||||
@@ -67,7 +74,9 @@
|
||||
# -p creates parents automatically
|
||||
default =
|
||||
let
|
||||
createOptions = (lib.optionalAttrs (config.mountpoint != null) { mountpoint = config.mountpoint; }) // config.options;
|
||||
createOptions =
|
||||
(lib.optionalAttrs (config.mountpoint != null) { mountpoint = config.mountpoint; })
|
||||
// config.options;
|
||||
# All options defined as PROP_ONETIME or PROP_ONETIME_DEFAULT in https://github.com/openzfs/zfs/blob/master/module/zcommon/zfs_prop.c
|
||||
onetimeProperties = [
|
||||
"encryption"
|
||||
@@ -83,16 +92,23 @@
|
||||
in
|
||||
''
|
||||
if ! zfs get type ${config._name} >/dev/null 2>&1; then
|
||||
${if config._createFilesystem then ''
|
||||
${
|
||||
if config._createFilesystem then
|
||||
''
|
||||
zfs create -up ${config._name} \
|
||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") (createOptions))}
|
||||
'' else ''
|
||||
''
|
||||
else
|
||||
''
|
||||
# don't create anything for root dataset of zpools
|
||||
true
|
||||
''}
|
||||
''
|
||||
}
|
||||
${lib.optionalString (updateOptions != { }) ''
|
||||
else
|
||||
zfs set -u ${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "${n}=${v}") updateOptions)} ${config._name}
|
||||
zfs set -u ${
|
||||
lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "${n}=${v}") updateOptions)
|
||||
} ${config._name}
|
||||
''}
|
||||
fi
|
||||
'';
|
||||
@@ -101,7 +117,16 @@
|
||||
_mount = diskoLib.mkMountOption {
|
||||
inherit config options;
|
||||
default =
|
||||
lib.optionalAttrs (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") {
|
||||
(lib.optionalAttrs (config.options.keylocation or "none" != "none") {
|
||||
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} = ''
|
||||
if ! findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
|
||||
mount ${config._name} "${rootMountPoint}${config.mountpoint}" \
|
||||
@@ -114,15 +139,35 @@
|
||||
};
|
||||
};
|
||||
|
||||
_unmount = diskoLib.mkUnmountOption {
|
||||
inherit config options;
|
||||
default =
|
||||
(lib.optionalAttrs (config.options.keylocation or "none" != "none") {
|
||||
dev = "zfs unload-key ${config.name}";
|
||||
})
|
||||
// lib.optionalAttrs
|
||||
(config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off")
|
||||
{
|
||||
fs.${config.mountpoint} = ''
|
||||
if findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
|
||||
umount "${rootMountPoint}${config.mountpoint}"
|
||||
fi
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
_config = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default =
|
||||
lib.optional (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") {
|
||||
lib.optional (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off")
|
||||
{
|
||||
fileSystems.${config.mountpoint} = {
|
||||
device = "${config._name}";
|
||||
fsType = "zfs";
|
||||
options = config.mountOptions ++ lib.optional ((config.options.mountpoint or "") != "legacy") "zfsutil";
|
||||
options =
|
||||
config.mountOptions
|
||||
++ lib.optional ((config.options.mountpoint or "") != "legacy") "zfsutil";
|
||||
};
|
||||
};
|
||||
description = "NixOS configuration";
|
||||
@@ -137,4 +182,3 @@
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
+51
-12
@@ -1,4 +1,11 @@
|
||||
{ config, options, lib, diskoLib, parent, ... }:
|
||||
{
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
diskoLib,
|
||||
parent,
|
||||
...
|
||||
}:
|
||||
{
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
@@ -17,6 +24,11 @@
|
||||
default = { };
|
||||
description = "Options to set for the dataset";
|
||||
};
|
||||
extraArgs = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
description = "Extra arguments passed to `zfs create`";
|
||||
};
|
||||
mountOptions = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ "defaults" ];
|
||||
@@ -30,7 +42,10 @@
|
||||
description = "Size of the dataset";
|
||||
};
|
||||
|
||||
content = diskoLib.partitionType { parent = config; device = "/dev/zvol/${config._parent.name}/${config.name}"; };
|
||||
content = diskoLib.partitionType {
|
||||
parent = config;
|
||||
device = "/dev/zvol/${config._parent.name}/${config.name}";
|
||||
};
|
||||
|
||||
_parent = lib.mkOption {
|
||||
internal = true;
|
||||
@@ -40,8 +55,7 @@
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = lib.types.functionTo diskoLib.jsonType;
|
||||
default = dev:
|
||||
lib.optionalAttrs (config.content != null) (config.content._meta dev);
|
||||
default = dev: lib.optionalAttrs (config.content != null) (config.content._meta dev);
|
||||
description = "Metadata";
|
||||
};
|
||||
_create = diskoLib.mkCreateOption {
|
||||
@@ -50,7 +64,7 @@
|
||||
if ! zfs get type "${config._parent.name}/${config.name}" >/dev/null 2>&1; then
|
||||
zfs create "${config._parent.name}/${config.name}" \
|
||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
|
||||
-V ${config.size}
|
||||
-V ${config.size} ${toString (builtins.map lib.escapeShellArg config.extraArgs)}
|
||||
zvol_wait
|
||||
partprobe "/dev/zvol/${config._parent.name}/${config.name}"
|
||||
udevadm trigger --subsystem-match=block
|
||||
@@ -61,26 +75,51 @@
|
||||
};
|
||||
_mount = diskoLib.mkMountOption {
|
||||
inherit config options;
|
||||
default =
|
||||
lib.optionalAttrs (config.content != null) config.content._mount;
|
||||
default = {
|
||||
dev = ''
|
||||
${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 {
|
||||
inherit config options;
|
||||
default = {
|
||||
dev = ''
|
||||
${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 {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
default =
|
||||
lib.optional (config.content != null) config.content._config;
|
||||
default = 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: [
|
||||
default =
|
||||
pkgs:
|
||||
[
|
||||
pkgs.util-linux
|
||||
pkgs.parted # for partprobe
|
||||
] ++ lib.optionals (config.content != null) (config.content._pkgs pkgs);
|
||||
]
|
||||
++ lib.optionals (config.content != null) (config.content._pkgs pkgs);
|
||||
description = "Packages";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
+220
-40
@@ -1,6 +1,13 @@
|
||||
{ config, options, lib, diskoLib, rootMountPoint, ... }:
|
||||
{
|
||||
config,
|
||||
options,
|
||||
lib,
|
||||
diskoLib,
|
||||
rootMountPoint,
|
||||
...
|
||||
}:
|
||||
let
|
||||
# TODO: Consider expanding to handle `disk` `file` and `draid` mode options.
|
||||
# TODO: Consider expanding to handle `file` and `draid` mode options.
|
||||
modeOptions = [
|
||||
""
|
||||
"mirror"
|
||||
@@ -25,13 +32,55 @@ in
|
||||
};
|
||||
mode = lib.mkOption {
|
||||
default = "";
|
||||
type = (lib.types.oneOf [
|
||||
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 [
|
||||
(lib.types.enum modeOptions)
|
||||
(lib.types.attrsOf (diskoLib.subType {
|
||||
(lib.types.attrsOf (
|
||||
diskoLib.subType {
|
||||
types = {
|
||||
topology =
|
||||
let
|
||||
vdev = lib.types.submodule ({ ... }: {
|
||||
vdev = lib.types.submodule (
|
||||
{ ... }:
|
||||
{
|
||||
options = {
|
||||
mode = lib.mkOption {
|
||||
type = lib.types.enum modeOptions;
|
||||
@@ -43,10 +92,12 @@ in
|
||||
description = "Members of the vdev";
|
||||
};
|
||||
};
|
||||
});
|
||||
}
|
||||
);
|
||||
in
|
||||
lib.types.submodule
|
||||
({ ... }: {
|
||||
lib.types.submodule (
|
||||
{ ... }:
|
||||
{
|
||||
options = {
|
||||
type = lib.mkOption {
|
||||
type = lib.types.enum [ "topology" ];
|
||||
@@ -63,19 +114,94 @@ in
|
||||
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Virtual_Devices_(vdevs)
|
||||
for details.
|
||||
'';
|
||||
example = [{
|
||||
example = [
|
||||
{
|
||||
mode = "mirror";
|
||||
members = [ "x" "y" "/dev/sda1" ];
|
||||
}];
|
||||
members = [
|
||||
"x"
|
||||
"y"
|
||||
];
|
||||
}
|
||||
{
|
||||
members = [ "z" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
spare = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
description = ''
|
||||
A list of devices to use as hot spares. See
|
||||
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Hot_Spares
|
||||
for details.
|
||||
'';
|
||||
example = [
|
||||
"x"
|
||||
"y"
|
||||
];
|
||||
};
|
||||
log = lib.mkOption {
|
||||
type = lib.types.listOf vdev;
|
||||
default = [ ];
|
||||
description = ''
|
||||
A list of vdevs used for the zfs intent log (ZIL). See
|
||||
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Intent_Log
|
||||
for details.
|
||||
'';
|
||||
example = [
|
||||
{
|
||||
mode = "mirror";
|
||||
members = [
|
||||
"x"
|
||||
"y"
|
||||
];
|
||||
}
|
||||
{
|
||||
members = [ "z" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
dedup = lib.mkOption {
|
||||
type = lib.types.listOf vdev;
|
||||
default = [ ];
|
||||
description = ''
|
||||
A list of vdevs used for the deduplication table. See
|
||||
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#dedup
|
||||
for details.
|
||||
'';
|
||||
example = [
|
||||
{
|
||||
mode = "mirror";
|
||||
members = [
|
||||
"x"
|
||||
"y"
|
||||
];
|
||||
}
|
||||
{
|
||||
members = [ "z" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
special = lib.mkOption {
|
||||
type = lib.types.nullOr vdev;
|
||||
default = null;
|
||||
type = lib.types.either (lib.types.listOf vdev) (lib.types.nullOr vdev);
|
||||
default = [ ];
|
||||
description = ''
|
||||
A vdev definition for a special device. See
|
||||
A list of vdevs used as special devices. See
|
||||
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#special
|
||||
for details.
|
||||
'';
|
||||
example = [
|
||||
{
|
||||
mode = "mirror";
|
||||
members = [
|
||||
"x"
|
||||
"y"
|
||||
];
|
||||
}
|
||||
{
|
||||
members = [ "z" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
cache = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
@@ -85,14 +211,20 @@ in
|
||||
https://openzfs.github.io/openzfs-docs/man/master/7/zpoolconcepts.7.html#Cache_Devices
|
||||
for details.
|
||||
'';
|
||||
example = [
|
||||
"x"
|
||||
"y"
|
||||
];
|
||||
};
|
||||
# TODO: Consider supporting log, spare, and dedup options.
|
||||
};
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
extraArgs.parent = config;
|
||||
}))
|
||||
]);
|
||||
}
|
||||
))
|
||||
]
|
||||
);
|
||||
description = "Mode of the ZFS pool";
|
||||
};
|
||||
options = lib.mkOption {
|
||||
@@ -116,31 +248,41 @@ in
|
||||
description = "Options to pass to mount";
|
||||
};
|
||||
datasets = lib.mkOption {
|
||||
type = lib.types.attrsOf (diskoLib.subType {
|
||||
type = lib.types.attrsOf (
|
||||
diskoLib.subType {
|
||||
types = { inherit (diskoLib.types) zfs_fs zfs_volume; };
|
||||
extraArgs.parent = config;
|
||||
});
|
||||
}
|
||||
);
|
||||
description = "List of datasets to define";
|
||||
};
|
||||
_meta = lib.mkOption {
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = diskoLib.jsonType;
|
||||
default =
|
||||
diskoLib.deepMergeMap (dataset: dataset._meta [ "zpool" config.name ]) (lib.attrValues config.datasets);
|
||||
default = diskoLib.deepMergeMap (
|
||||
dataset:
|
||||
dataset._meta [
|
||||
"zpool"
|
||||
config.name
|
||||
]
|
||||
) (lib.attrValues config.datasets);
|
||||
description = "Metadata";
|
||||
};
|
||||
_create = diskoLib.mkCreateOption {
|
||||
inherit config options;
|
||||
default =
|
||||
let
|
||||
formatOutput = mode: members: ''
|
||||
entries+=("${mode}=${
|
||||
lib.concatMapStringsSep " "
|
||||
(d: if lib.strings.hasPrefix "/" d then d else "/dev/disk/by-partlabel/disk-${d}-zfs") members
|
||||
formatOutput = type: mode: members: ''
|
||||
entries+=("${type} ${mode}=${
|
||||
lib.concatMapStringsSep " " (
|
||||
d: if lib.strings.hasPrefix "/" d then d else "/dev/disk/by-partlabel/disk-${d}-zfs"
|
||||
) members
|
||||
}")
|
||||
'';
|
||||
formatVdev = vdev: formatOutput vdev.mode vdev.members;
|
||||
formatVdev = type: vdev: formatOutput type vdev.mode vdev.members;
|
||||
formatVdevList =
|
||||
type: vdevs: lib.concatMapStrings (formatVdev type) (builtins.sort (a: _: a.mode == "") vdevs);
|
||||
hasTopology = !(builtins.isString config.mode);
|
||||
mode = if hasTopology then "prescribed" else config.mode;
|
||||
topology = lib.optionalAttrs hasTopology config.mode.topology;
|
||||
@@ -180,19 +322,34 @@ in
|
||||
topology="${mode} ''${zfs_devices[*]}"
|
||||
else
|
||||
entries=()
|
||||
${lib.optionalString (hasTopology && topology.vdev != null)
|
||||
(lib.concatMapStrings formatVdev topology.vdev)}
|
||||
${lib.optionalString (hasTopology && topology.special != null)
|
||||
(formatOutput "special ${topology.special.mode}" topology.special.members)}
|
||||
${lib.optionalString (hasTopology && topology.cache != [])
|
||||
(formatOutput "cache" topology.cache)}
|
||||
${lib.optionalString (hasTopology && topology.vdev != null) (formatVdevList "" topology.vdev)}
|
||||
${lib.optionalString (hasTopology && topology.spare != [ ]) (
|
||||
formatOutput "spare" "" topology.spare
|
||||
)}
|
||||
${lib.optionalString (hasTopology && topology.log != [ ]) (formatVdevList "log" topology.log)}
|
||||
${lib.optionalString (hasTopology && topology.dedup != [ ]) (
|
||||
formatVdevList "dedup" topology.dedup
|
||||
)}
|
||||
${lib.optionalString (hasTopology && topology.special != null && topology.special != [ ]) (
|
||||
formatVdevList "special" (lib.lists.toList topology.special)
|
||||
)}
|
||||
${lib.optionalString (hasTopology && topology.cache != [ ]) (
|
||||
formatOutput "cache" "" topology.cache
|
||||
)}
|
||||
all_devices=()
|
||||
last_type=
|
||||
for line in "''${entries[@]}"; do
|
||||
# lineformat is mode=device1 device2 device3
|
||||
mode=''${line%%=*}
|
||||
devs=''${line#*=}
|
||||
# lineformat is type mode=device1 device2 device3
|
||||
mode="''${line%%=*}"
|
||||
type="''${mode%% *}"
|
||||
mode="''${mode#"$type "}"
|
||||
devs="''${line#*=}"
|
||||
IFS=' ' read -r -a devices <<< "$devs"
|
||||
all_devices+=("''${devices[@]}")
|
||||
if ! [ "$type" = "$last_type" ]; then
|
||||
topology+=" $type"
|
||||
last_type="$type"
|
||||
fi
|
||||
topology+=" ''${mode} ''${devices[*]}"
|
||||
done
|
||||
# all_devices sorted should equal zfs_devices sorted
|
||||
@@ -223,15 +380,31 @@ in
|
||||
inherit config options;
|
||||
default =
|
||||
let
|
||||
datasetMounts = diskoLib.deepMergeMap (dataset: dataset._mount) (lib.attrValues config.datasets);
|
||||
datasetFilesystemsMounts = diskoLib.deepMergeMap (dataset: dataset._mount.fs or { }) (
|
||||
lib.attrValues config.datasets
|
||||
);
|
||||
in
|
||||
{
|
||||
dev = ''
|
||||
zpool list "${config.name}" >/dev/null 2>/dev/null ||
|
||||
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 = datasetMounts.fs or { };
|
||||
fs = datasetFilesystemsMounts;
|
||||
};
|
||||
};
|
||||
_unmount = diskoLib.mkUnmountOption {
|
||||
inherit config options;
|
||||
default = {
|
||||
dev = ''
|
||||
${lib.concatMapStrings (dataset: dataset._unmount.dev or "") (lib.attrValues config.datasets)}
|
||||
|
||||
if zpool list "${config.name}" >/dev/null 2>/dev/null; then
|
||||
zpool export "${config.name}"
|
||||
fi
|
||||
'';
|
||||
fs = diskoLib.deepMergeMap (dataset: dataset._unmount.fs or { }) (lib.attrValues config.datasets);
|
||||
};
|
||||
};
|
||||
_config = lib.mkOption {
|
||||
@@ -244,7 +417,13 @@ in
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||
default = pkgs: [ pkgs.gnugrep pkgs.util-linux ] ++ lib.flatten (map (dataset: dataset._pkgs pkgs) (lib.attrValues config.datasets));
|
||||
default =
|
||||
pkgs:
|
||||
[
|
||||
pkgs.gnugrep
|
||||
pkgs.util-linux
|
||||
]
|
||||
++ lib.flatten (map (dataset: dataset._pkgs pkgs) (lib.attrValues config.datasets));
|
||||
description = "Packages";
|
||||
};
|
||||
};
|
||||
@@ -256,6 +435,7 @@ in
|
||||
type = "zfs_fs";
|
||||
mountpoint = config.mountpoint;
|
||||
options = config.rootFsOptions;
|
||||
mountOptions = config.mountOptions;
|
||||
};
|
||||
};
|
||||
}
|
||||
+65
-15
@@ -1,4 +1,11 @@
|
||||
{ config, lib, pkgs, extendModules, diskoLib, ... }:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
extendModules,
|
||||
diskoLib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.disko;
|
||||
|
||||
@@ -14,6 +21,15 @@ in
|
||||
|
||||
options.disko = {
|
||||
imageBuilder = {
|
||||
enableBinfmt = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
description = ''
|
||||
enable emulation of foreign architecture binaries in the builder.
|
||||
Makes it possible to build disk images for a foreign architecture in a VM with native performance.
|
||||
Required for the bootloader installation step, which chroots into the target environment.
|
||||
'';
|
||||
default = false;
|
||||
};
|
||||
qemu = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
description = ''
|
||||
@@ -59,9 +75,9 @@ in
|
||||
extraPostVM = lib.mkOption {
|
||||
type = lib.types.lines;
|
||||
description = ''
|
||||
extra shell code to execute once the disk image(s) have been succesfully created and moved to $out
|
||||
extra shell code to execute once the disk image(s) have been successfully created and moved to $out
|
||||
'';
|
||||
default = "";
|
||||
default = ":";
|
||||
example = lib.literalExpression ''
|
||||
''${pkgs.zstd}/bin/zstd --compress $out/*raw
|
||||
rm $out/*raw
|
||||
@@ -98,7 +114,10 @@ in
|
||||
};
|
||||
|
||||
imageFormat = lib.mkOption {
|
||||
type = lib.types.enum [ "raw" "qcow2" ];
|
||||
type = lib.types.enum [
|
||||
"raw"
|
||||
"qcow2"
|
||||
];
|
||||
description = "QEMU image format to use for the disk images";
|
||||
default = "raw";
|
||||
};
|
||||
@@ -153,6 +172,15 @@ in
|
||||
};
|
||||
|
||||
tests = {
|
||||
bootCommands = lib.mkOption {
|
||||
description = ''
|
||||
NixOS test script commands to run after the machine has started. Can
|
||||
be used to enter an interactive password.
|
||||
'';
|
||||
type = lib.types.lines;
|
||||
default = "";
|
||||
};
|
||||
|
||||
efi = lib.mkOption {
|
||||
description = ''
|
||||
Whether efi is enabled for the `system.build.installTest`.
|
||||
@@ -163,6 +191,14 @@ in
|
||||
default = config.boot.loader.systemd-boot.enable || config.boot.loader.grub.efiSupport;
|
||||
};
|
||||
|
||||
enableOCR = lib.mkOption {
|
||||
description = ''
|
||||
Sets the enableOCR option in the NixOS VM test driver.
|
||||
'';
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
};
|
||||
|
||||
extraChecks = lib.mkOption {
|
||||
description = ''
|
||||
extra checks to run in the `system.build.installTest`.
|
||||
@@ -196,7 +232,7 @@ in
|
||||
config = {
|
||||
assertions = [
|
||||
{
|
||||
assertion = config.disko.imageBuilder.qemu != null -> diskoLib.vmToolsSupportsCustomQemu pkgs;
|
||||
assertion = config.disko.imageBuilder.qemu != null -> diskoLib.vmToolsSupportsCustomQemu lib;
|
||||
message = ''
|
||||
You have set config.disko.imageBuild.qemu, but vmTools in your nixpkgs version "${lib.version}"
|
||||
does not support overriding the qemu package with the customQemu option yet.
|
||||
@@ -205,6 +241,7 @@ in
|
||||
}
|
||||
];
|
||||
|
||||
_module.args.imagePkgs = pkgs;
|
||||
_module.args.diskoLib = import ./lib {
|
||||
inherit lib;
|
||||
rootMountPoint = config.disko.rootMountPoint;
|
||||
@@ -212,21 +249,37 @@ in
|
||||
eval-config = import (pkgs.path + "/nixos/lib/eval-config.nix");
|
||||
};
|
||||
|
||||
system.build = (cfg.devices._scripts { inherit pkgs; checked = cfg.checkScripts; }) // (
|
||||
system.build =
|
||||
(cfg.devices._scripts {
|
||||
inherit pkgs;
|
||||
checked = cfg.checkScripts;
|
||||
})
|
||||
// (
|
||||
let
|
||||
throwIfNoDisksDetected = _: v: if cfg.devices.disk == { } then throw "No disks defined, did you forget to import your disko config?" else v;
|
||||
throwIfNoDisksDetected =
|
||||
_: v:
|
||||
if cfg.devices.disk == { } then
|
||||
throw "No disks defined, did you forget to import your disko config?"
|
||||
else
|
||||
v;
|
||||
in
|
||||
lib.mapAttrs throwIfNoDisksDetected {
|
||||
# we keep these old outputs for compatibility
|
||||
disko = builtins.trace "the .disko output is deprecated, please use .diskoScript instead" (cfg.devices._scripts { inherit pkgs; }).diskoScript;
|
||||
diskoNoDeps = builtins.trace "the .diskoNoDeps output is deprecated, please use .diskoScriptNoDeps instead" (cfg.devices._scripts { inherit pkgs; }).diskoScriptNoDeps;
|
||||
disko =
|
||||
builtins.trace "the .disko output is deprecated, please use .diskoScript instead"
|
||||
(cfg.devices._scripts { inherit pkgs; }).diskoScript;
|
||||
diskoNoDeps =
|
||||
builtins.trace "the .diskoNoDeps output is deprecated, please use .diskoScriptNoDeps instead"
|
||||
(cfg.devices._scripts { inherit pkgs; }).diskoScriptNoDeps;
|
||||
|
||||
installTest = diskoLib.testLib.makeDiskoTest {
|
||||
inherit extendModules pkgs;
|
||||
name = "${config.networking.hostName}-disko";
|
||||
disko-config = builtins.removeAttrs config [ "_module" ];
|
||||
testMode = "direct";
|
||||
bootCommands = cfg.tests.bootCommands;
|
||||
efi = cfg.tests.efi;
|
||||
enableOCR = cfg.tests.enableOCR;
|
||||
extraSystemConfig = cfg.tests.extraConfig;
|
||||
extraTestScript = cfg.tests.extraChecks;
|
||||
};
|
||||
@@ -237,11 +290,8 @@ in
|
||||
|
||||
# we need to specify the keys here, so we don't get an infinite recursion error
|
||||
# Remember to add config keys here if they are added to types
|
||||
fileSystems = lib.mkIf
|
||||
cfg.enableConfig cfg.devices._config.fileSystems or { };
|
||||
boot = lib.mkIf
|
||||
cfg.enableConfig cfg.devices._config.boot or { };
|
||||
swapDevices = lib.mkIf
|
||||
cfg.enableConfig cfg.devices._config.swapDevices or [ ];
|
||||
fileSystems = lib.mkIf cfg.enableConfig cfg.devices._config.fileSystems or { };
|
||||
boot = lib.mkIf cfg.enableConfig cfg.devices._config.boot or { };
|
||||
swapDevices = lib.mkIf cfg.enableConfig cfg.devices._config.swapDevices or [ ];
|
||||
};
|
||||
}
|
||||
+18
-2
@@ -1,4 +1,14 @@
|
||||
{ stdenvNoCC, makeWrapper, lib, path, nix, coreutils, nixos-install-tools, binlore, diskoVersion }:
|
||||
{
|
||||
stdenvNoCC,
|
||||
makeWrapper,
|
||||
lib,
|
||||
path,
|
||||
nix,
|
||||
coreutils,
|
||||
nixos-install-tools,
|
||||
binlore,
|
||||
diskoVersion,
|
||||
}:
|
||||
|
||||
let
|
||||
self = stdenvNoCC.mkDerivation (finalAttrs: {
|
||||
@@ -16,7 +26,13 @@ let
|
||||
chmod 755 "$out/bin/$i"
|
||||
wrapProgram "$out/bin/$i" \
|
||||
--set DISKO_VERSION "${diskoVersion}" \
|
||||
--prefix PATH : ${lib.makeBinPath [ nix coreutils nixos-install-tools ]} \
|
||||
--prefix PATH : ${
|
||||
lib.makeBinPath [
|
||||
nix
|
||||
coreutils
|
||||
nixos-install-tools
|
||||
]
|
||||
} \
|
||||
--prefix NIX_PATH : "nixpkgs=${path}"
|
||||
done
|
||||
'';
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#! /usr/bin/env bash
|
||||
|
||||
# Don't run directly! Instead, use
|
||||
# nix run .#create-release
|
||||
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
@@ -17,4 +18,3 @@ diskoLib.testLib.makeDiskoTest {
|
||||
machine.succeed("test -e /partition-root/swapfile1");
|
||||
'';
|
||||
}
|
||||
|
||||
+8
-4
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
@@ -18,7 +19,7 @@ diskoLib.testLib.makeDiskoTest {
|
||||
machine.succeed("mountpoint /zfs_fs");
|
||||
machine.succeed("mountpoint /zfs_legacy_fs");
|
||||
machine.succeed("mountpoint /ext4onzfs");
|
||||
machine.succeed("mountpoint /ext4_on_lvm");
|
||||
machine.succeed("mountpoint /exfat_on_lvm");
|
||||
'';
|
||||
extraSystemConfig = {
|
||||
imports = [
|
||||
@@ -26,7 +27,10 @@ diskoLib.testLib.makeDiskoTest {
|
||||
];
|
||||
};
|
||||
extraInstallerConfig = {
|
||||
boot.kernelModules = [ "dm-raid" "dm-mirror" ];
|
||||
boot.kernelModules = [
|
||||
"dm-raid"
|
||||
"dm-mirror"
|
||||
];
|
||||
imports = [
|
||||
../module.nix
|
||||
];
|
||||
|
||||
+10
-6
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
@@ -13,17 +14,20 @@ diskoLib.testLib.makeDiskoTest {
|
||||
};
|
||||
extraTestScript = ''
|
||||
machine.succeed("test -b /dev/md/raid1p1");
|
||||
|
||||
machine.succeed("test -b /dev/disk/by-partuuid/f0f0f0f0-f0f0-f0f0-f0f0-f0f0f0f0f0f0")
|
||||
|
||||
machine.succeed("mountpoint /zfs_fs");
|
||||
machine.succeed("mountpoint /zfs_legacy_fs");
|
||||
machine.succeed("mountpoint /ext4onzfs");
|
||||
machine.succeed("mountpoint /ext4_on_lvm");
|
||||
machine.succeed("mountpoint /exfat_on_lvm");
|
||||
|
||||
|
||||
machine.succeed("test -e /ext4_on_lvm/file-from-postMountHook");
|
||||
machine.succeed("test -e /exfat_on_lvm/file-from-postMountHook");
|
||||
'';
|
||||
extraInstallerConfig = {
|
||||
boot.kernelModules = [ "dm-raid" "dm-mirror" ];
|
||||
boot.kernelModules = [
|
||||
"dm-raid"
|
||||
"dm-mirror"
|
||||
];
|
||||
};
|
||||
}
|
||||
+18
-10
@@ -1,20 +1,28 @@
|
||||
{ makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>
|
||||
, eval-config ? import <nixpkgs/nixos/lib/eval-config.nix>
|
||||
, pkgs ? import <nixpkgs> { }
|
||||
{
|
||||
makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>,
|
||||
eval-config ? import <nixpkgs/nixos/lib/eval-config.nix>,
|
||||
pkgs ? import <nixpkgs> { },
|
||||
}:
|
||||
let
|
||||
lib = pkgs.lib;
|
||||
diskoLib = import ../lib { inherit lib makeTest eval-config; };
|
||||
|
||||
allTestFilenames =
|
||||
builtins.map (lib.removeSuffix ".nix") (
|
||||
builtins.filter
|
||||
(x: lib.hasSuffix ".nix" x && x != "default.nix")
|
||||
(lib.attrNames (builtins.readDir ./.))
|
||||
allTestFilenames = builtins.map (lib.removeSuffix ".nix") (
|
||||
builtins.filter (x: lib.hasSuffix ".nix" x && x != "default.nix") (
|
||||
lib.attrNames (builtins.readDir ./.)
|
||||
)
|
||||
);
|
||||
incompatibleTests = lib.optionals pkgs.buildPlatform.isRiscV64 [ "zfs" "zfs-over-legacy" "cli" "module" "complex" ];
|
||||
incompatibleTests = lib.optionals pkgs.stdenv.buildPlatform.isRiscV64 [
|
||||
"zfs"
|
||||
"zfs-over-legacy"
|
||||
"cli"
|
||||
"module"
|
||||
"complex"
|
||||
];
|
||||
allCompatibleFilenames = lib.subtractLists incompatibleTests allTestFilenames;
|
||||
|
||||
allTests = lib.genAttrs allCompatibleFilenames (test: import (./. + "/${test}.nix") { inherit diskoLib pkgs; });
|
||||
allTests = lib.genAttrs allCompatibleFilenames (
|
||||
test: import (./. + "/${test}.nix") { inherit diskoLib pkgs; }
|
||||
);
|
||||
in
|
||||
allTests
|
||||
@@ -1,4 +1,10 @@
|
||||
{ lib, pkgs, modulesPath, ... }: {
|
||||
{
|
||||
lib,
|
||||
pkgs,
|
||||
modulesPath,
|
||||
...
|
||||
}:
|
||||
{
|
||||
imports = [
|
||||
(modulesPath + "/testing/test-instrumentation.nix")
|
||||
(modulesPath + "/profiles/qemu-guest.nix")
|
||||
@@ -13,11 +19,22 @@
|
||||
hashed-mirrors = null;
|
||||
connect-timeout = 3;
|
||||
flake-registry = pkgs.writeText "flake-registry" ''{"flakes":[],"version":2}'';
|
||||
experimental-features = [ "nix-command" "flakes" ];
|
||||
experimental-features = [
|
||||
"nix-command"
|
||||
"flakes"
|
||||
];
|
||||
};
|
||||
services.openssh.enable = true;
|
||||
boot.kernelParams = [ "console=tty0" ] ++
|
||||
(lib.optional (pkgs.stdenv.hostPlatform.isAarch) "ttyAMA0,115200") ++
|
||||
(lib.optional (pkgs.stdenv.hostPlatform.isRiscV64) "ttySIF0,115200") ++
|
||||
[ "console=ttyS0,115200" ];
|
||||
boot.kernelParams =
|
||||
[ "console=tty0" ]
|
||||
++ (lib.optional (pkgs.stdenv.hostPlatform.isAarch) "ttyAMA0,115200")
|
||||
++ (lib.optional (pkgs.stdenv.hostPlatform.isRiscV64) "ttySIF0,115200")
|
||||
++ [ "console=ttyS0,115200" ];
|
||||
|
||||
# reduce closure size
|
||||
nixpkgs.flake.setFlakeRegistry = false;
|
||||
nixpkgs.flake.setNixPath = false;
|
||||
nix.registry.nixpkgs.to = { };
|
||||
documentation.doc.enable = false;
|
||||
documentation.man.enable = false;
|
||||
}
|
||||
@@ -1,10 +1,19 @@
|
||||
{ pkgs ? import <nixpkgs> { }, self, diskoVersion }:
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
self,
|
||||
diskoVersion,
|
||||
}:
|
||||
let
|
||||
disko = pkgs.callPackage ../../package.nix { inherit diskoVersion; };
|
||||
|
||||
dependencies = [
|
||||
self.nixosConfigurations.testmachine.pkgs.stdenv.drvPath
|
||||
(self.nixosConfigurations.testmachine.pkgs.closureInfo { rootPaths = [ ]; }).drvPath
|
||||
|
||||
# https://github.com/NixOS/nixpkgs/blob/f2fd33a198a58c4f3d53213f01432e4d88474956/nixos/modules/system/activation/top-level.nix#L342
|
||||
self.nixosConfigurations.testmachine.pkgs.perlPackages.ConfigIniFiles
|
||||
self.nixosConfigurations.testmachine.pkgs.perlPackages.FileSlurp
|
||||
|
||||
self.nixosConfigurations.testmachine.config.system.build.toplevel
|
||||
self.nixosConfigurations.testmachine.config.system.build.diskoScript
|
||||
] ++ builtins.map (i: i.outPath) (builtins.attrValues self.inputs);
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
name = "gpt-unformatted";
|
||||
disko-config = ../example/gpt-unformatted.nix;
|
||||
extraTestScript = ''
|
||||
machine.succeed("mountpoint /");
|
||||
'';
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
name = "luks-interactive-login";
|
||||
disko-config = ../example/luks-interactive-login.nix;
|
||||
enableOCR = true;
|
||||
extraTestScript = ''
|
||||
machine.succeed("cryptsetup isLuks /dev/vda2");
|
||||
'';
|
||||
bootCommands = ''
|
||||
machine.wait_for_console_text("vda")
|
||||
machine.send_console("secretsecret\n")
|
||||
machine.wait_for_text("[Pp]assphrase for")
|
||||
machine.send_chars("secretsecret\n")
|
||||
'';
|
||||
}
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
+8
-3
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
@@ -9,7 +10,11 @@ diskoLib.testLib.makeDiskoTest {
|
||||
machine.succeed("mountpoint /home");
|
||||
'';
|
||||
extraInstallerConfig = {
|
||||
boot.kernelModules = [ "dm-raid" "raid0" "dm-mirror" ];
|
||||
boot.kernelModules = [
|
||||
"dm-raid"
|
||||
"raid0"
|
||||
"dm-mirror"
|
||||
];
|
||||
};
|
||||
extraSystemConfig = {
|
||||
# sadly systemd-boot fails to install to a raid /boot device
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, ...
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
...
|
||||
}:
|
||||
|
||||
(pkgs.nixos [
|
||||
../module.nix
|
||||
../example/simple-efi.nix
|
||||
({ config, ... }: {
|
||||
(
|
||||
{ config, ... }:
|
||||
{
|
||||
documentation.enable = false;
|
||||
system.stateVersion = config.system.nixos.version;
|
||||
disko.checkScripts = true;
|
||||
})
|
||||
}
|
||||
)
|
||||
]).config.system.build.diskoImagesScript
|
||||
@@ -1,14 +1,18 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, ...
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
...
|
||||
}:
|
||||
|
||||
(pkgs.nixos [
|
||||
../module.nix
|
||||
../example/simple-efi.nix
|
||||
({ config, ... }: {
|
||||
(
|
||||
{ config, ... }:
|
||||
{
|
||||
documentation.enable = false;
|
||||
system.stateVersion = config.system.nixos.version;
|
||||
disko.memSize = 2048;
|
||||
disko.checkScripts = true;
|
||||
})
|
||||
}
|
||||
)
|
||||
]).config.system.build.diskoImages
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
+7
-3
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
@@ -21,6 +22,9 @@ diskoLib.testLib.makeDiskoTest {
|
||||
machine.succeed("mountpoint /ext4_on_lvm");
|
||||
'';
|
||||
extraInstallerConfig = {
|
||||
boot.kernelModules = [ "dm-raid" "dm-mirror" ];
|
||||
boot.kernelModules = [
|
||||
"dm-raid"
|
||||
"dm-mirror"
|
||||
];
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
# this is a regression test for https://github.com/nix-community/disko/issues/52
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# this is a regression test for https://github.com/nix-community/disko/issues/52
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
{ pkgs ? import <nixpkgs> { }, ... }:
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
...
|
||||
}:
|
||||
(pkgs.nixos [
|
||||
../example/stand-alone/configuration.nix
|
||||
{ documentation.enable = false; }
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
+3
-2
@@ -1,5 +1,6 @@
|
||||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
{
|
||||
pkgs ? import <nixpkgs> { },
|
||||
diskoLib ? pkgs.callPackage ../lib { },
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
|
||||
Loaded 100 of 108 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user