mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 21:13:28 +01:00
Compare commits
38
Commits
images-doc
..
mdadm
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5874ca3ea | ||
|
|
5b7c6aafff | ||
|
|
b8785a1c37 | ||
|
|
1efd500e98 | ||
|
|
d51114dc1b | ||
|
|
93bf2c3d26 | ||
|
|
bb5ba68ebb | ||
|
|
8d4ae698ea | ||
|
|
a297cb1cb0 | ||
|
|
53c4cc48b7 | ||
|
|
07b7d662d8 | ||
|
|
79eab0e82c | ||
|
|
9e0bf2fe7f | ||
|
|
e18e85ba3f | ||
|
|
89b617b99d | ||
|
|
0a17298c0d | ||
|
|
fbbac1aee6 | ||
|
|
9fd80a030b | ||
|
|
1bdd6edc15 | ||
|
|
611c9ea532 | ||
|
|
502241afa3 | ||
|
|
a6717b1afe | ||
|
|
5d2d3e421a | ||
|
|
307365d9f9 | ||
|
|
a8c966ee11 | ||
|
|
f6f2e009d6 | ||
|
|
1efdc66977 | ||
|
|
e9875b9690 | ||
|
|
b7a91b50fd | ||
|
|
c09c3a9639 | ||
|
|
21d89b333c | ||
|
|
cc69c2340b | ||
|
|
59e50d4ecb | ||
|
|
f6b72bfed7 | ||
|
|
fe064a6393 | ||
|
|
a949edef70 | ||
|
|
5866ae41f7 | ||
|
|
7d25dc74c5 |
No files matched your search
@@ -13,7 +13,7 @@ jobs:
|
|||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
- name: Install Nix
|
- name: Install Nix
|
||||||
uses: cachix/install-nix-action@v25
|
uses: cachix/install-nix-action@v26
|
||||||
- name: Update flake.lock
|
- name: Update flake.lock
|
||||||
uses: DeterminateSystems/update-flake-lock@v21
|
uses: DeterminateSystems/update-flake-lock@v21
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -92,12 +92,12 @@ A simple disko configuration may look like this:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
If you'd saved this configuration in /tmp/disko-config.nix, and wanted to create
|
If you'd saved this configuration in /tmp/disk-config.nix, and wanted to create
|
||||||
a disk named /dev/sda, you would run the following command to partition,
|
a disk named /dev/sda, you would run the following command to partition,
|
||||||
format and mount the disk.
|
format and mount the disk.
|
||||||
|
|
||||||
```console
|
```console
|
||||||
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko /tmp/disko-config.nix
|
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko /tmp/disk-config.nix
|
||||||
```
|
```
|
||||||
|
|
||||||
## Related Tools
|
## Related Tools
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -efux -o pipefail
|
set -efux -o pipefail
|
||||||
# dependencies: bash jq util-linux lvm2 mdadm zfs
|
# dependencies: bash jq util-linux lvm2 mdadm zfs gnugrep sed
|
||||||
disk=$(realpath "$1")
|
disk=$(realpath "$1")
|
||||||
|
|
||||||
lsblk -a -f >&2
|
lsblk -a -f >&2
|
||||||
|
|||||||
@@ -104,6 +104,14 @@ while [[ $# -gt 0 ]]; do
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
nixBuild() {
|
||||||
|
if command -v nom-build > /dev/null; then
|
||||||
|
nom-build "$@"
|
||||||
|
else
|
||||||
|
nix-build "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
if ! { [[ $mode = "format" ]] || [[ $mode = "mount" ]] || [[ $mode = "disko" ]] || [[ $mode = "create" ]] || [[ $mode = "zap_create_mount" ]] ; }; then
|
if ! { [[ $mode = "format" ]] || [[ $mode = "mount" ]] || [[ $mode = "disko" ]] || [[ $mode = "create" ]] || [[ $mode = "zap_create_mount" ]] ; }; then
|
||||||
abort "mode must be either format, mount or disko"
|
abort "mode must be either format, mount or disko"
|
||||||
fi
|
fi
|
||||||
@@ -118,6 +126,9 @@ if [[ -n "${flake+x}" ]]; then
|
|||||||
echo "For example, to use the output diskoConfigurations.foo from the flake.nix, append \"#foo\" to the flake-uri."
|
echo "For example, to use the output diskoConfigurations.foo from the flake.nix, append \"#foo\" to the flake-uri."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if [[ -e "$flake" ]]; then
|
||||||
|
flake=$(realpath "$flake")
|
||||||
|
fi
|
||||||
nix_args+=("--arg" "flake" "\"$flake\"")
|
nix_args+=("--arg" "flake" "\"$flake\"")
|
||||||
nix_args+=("--argstr" "flakeAttr" "$flakeAttr")
|
nix_args+=("--argstr" "flakeAttr" "$flakeAttr")
|
||||||
nix_args+=(--extra-experimental-features flakes)
|
nix_args+=(--extra-experimental-features flakes)
|
||||||
@@ -128,7 +139,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# The "--impure" is still pure, as the path is within the nix store.
|
# The "--impure" is still pure, as the path is within the nix store.
|
||||||
script=$(nix-build "${libexec_dir}"/cli.nix \
|
script=$(nixBuild "${libexec_dir}"/cli.nix \
|
||||||
--no-out-link \
|
--no-out-link \
|
||||||
--impure \
|
--impure \
|
||||||
--argstr mode "$mode" \
|
--argstr mode "$mode" \
|
||||||
|
|||||||
+23
-2
@@ -6,6 +6,9 @@ showUsage() {
|
|||||||
cat <<EOF
|
cat <<EOF
|
||||||
Usage: $0 [OPTIONS]
|
Usage: $0 [OPTIONS]
|
||||||
--mode MODE Specify the mode of operation. Valid modes are: format, mount.
|
--mode MODE Specify the mode of operation. Valid modes are: format, mount.
|
||||||
|
Format will format the disk before installing.
|
||||||
|
Mount will mount the disk before installing.
|
||||||
|
Mount is useful for updating an existing system without losing data.
|
||||||
-f, --flake FLAKE_URI#ATTR Use the specified flake to install the NixOS configuration.
|
-f, --flake FLAKE_URI#ATTR Use the specified flake to install the NixOS configuration.
|
||||||
--disk NAME DEVICE Map the specified disk name to the specified device path.
|
--disk NAME DEVICE Map the specified disk name to the specified device path.
|
||||||
--dry-run Print the commands that would be run, but do not run them.
|
--dry-run Print the commands that would be run, but do not run them.
|
||||||
@@ -90,7 +93,6 @@ parseArgs() {
|
|||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
mode=$2
|
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--extra-files)
|
--extra-files)
|
||||||
@@ -139,6 +141,14 @@ cleanupMountPoint() {
|
|||||||
rmdir "${mountPoint}"
|
rmdir "${mountPoint}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nixBuild() {
|
||||||
|
if command -v nom-build > /dev/null; then
|
||||||
|
nom-build "$@"
|
||||||
|
else
|
||||||
|
nix-build "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
parseArgs "$@"
|
parseArgs "$@"
|
||||||
|
|
||||||
@@ -147,10 +157,21 @@ main() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# check if we are root
|
||||||
|
if [[ "$EUID" -ne 0 ]]; then
|
||||||
|
echo "This script must be run as root" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then
|
if [[ $flake =~ ^(.*)\#([^\#\"]*)$ ]]; then
|
||||||
flake="${BASH_REMATCH[1]}"
|
flake="${BASH_REMATCH[1]}"
|
||||||
flakeAttr="${BASH_REMATCH[2]}"
|
flakeAttr="${BASH_REMATCH[2]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -e "$flake" ]]; then
|
||||||
|
flake=$(realpath "$flake")
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -z ${flakeAttr-} ]]; then
|
if [[ -z ${flakeAttr-} ]]; then
|
||||||
echo "Please specify the name of the NixOS configuration to be installed, as a URI fragment in the flake-uri." >&2
|
echo "Please specify the name of the NixOS configuration to be installed, as a URI fragment in the flake-uri." >&2
|
||||||
echo 'For example, to use the output nixosConfigurations.foo from the flake.nix, append "#foo" to the flake-uri.' >&2
|
echo 'For example, to use the output nixosConfigurations.foo from the flake.nix, append "#foo" to the flake-uri.' >&2
|
||||||
@@ -163,7 +184,7 @@ main() {
|
|||||||
# shellcheck disable=SC2064
|
# shellcheck disable=SC2064
|
||||||
trap "cleanupMountPoint ${escapeMountPoint}" EXIT
|
trap "cleanupMountPoint ${escapeMountPoint}" EXIT
|
||||||
|
|
||||||
outputs=$(nix-build "${libexec_dir}"/install-cli.nix \
|
outputs=$(nixBuild "${libexec_dir}"/install-cli.nix \
|
||||||
"${nix_args[@]}" \
|
"${nix_args[@]}" \
|
||||||
--no-out-link \
|
--no-out-link \
|
||||||
--impure \
|
--impure \
|
||||||
|
|||||||
+25
-2
@@ -53,7 +53,30 @@ Then add the following to your configuration.nix in the `imports` list:
|
|||||||
|
|
||||||
```nix
|
```nix
|
||||||
{
|
{
|
||||||
imports = [ "${(import ./nix/sources.nix).disko}/modules/disko.nix" ];
|
imports = [ "${(import ./nix/sources.nix).disko}/module.nix" ];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>npins</summary>
|
||||||
|
|
||||||
|
First add it to [npins](https://github.com/andir/npins):
|
||||||
|
|
||||||
|
```console
|
||||||
|
npins add github nix-community disko
|
||||||
|
```
|
||||||
|
|
||||||
|
Then add the following to your configuration.nix in the `imports` list:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
let
|
||||||
|
sources = import ./npins;
|
||||||
|
disko = import sources.disko {};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
imports = [ "${disko}/module.nix" ];
|
||||||
|
…
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -72,7 +95,7 @@ Then add the following to your configuration.nix in the `imports` list:
|
|||||||
|
|
||||||
```nix
|
```nix
|
||||||
{
|
{
|
||||||
imports = [ <disko/modules/disko.nix> ];
|
imports = [ <disko/module.nix> ];
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -125,3 +125,89 @@ $ sudo nix run 'github:nix-community/disko#disko-install' -- --write-efi-boot-en
|
|||||||
|
|
||||||
This command installs NixOS with **disko-install** and sets the newly installed system as the default boot option,
|
This command installs NixOS with **disko-install** and sets the newly installed system as the default boot option,
|
||||||
without affecting the flexibility to boot from other devices if needed.
|
without affecting the flexibility to boot from other devices if needed.
|
||||||
|
|
||||||
|
### Using disko-install in an offline installer
|
||||||
|
|
||||||
|
If you want to **disko-install** from a customer installer without internet, you need to make sure that
|
||||||
|
next the toplevel of your NixOS closure that you plan to install, it also needs **diskoScript** and
|
||||||
|
all the flake inputs for evaluation.
|
||||||
|
|
||||||
|
#### Example configuration to install
|
||||||
|
|
||||||
|
Add this to your flake.nix output:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
{
|
||||||
|
nixosConfigurations.your-machine = inputs.nixpkgs.lib.nixosSystem {
|
||||||
|
system = "x86_64-linux";
|
||||||
|
modules = [
|
||||||
|
{
|
||||||
|
# TODO: add your NixOS configuration here, don't forget your hardware-configuration.nix as well!
|
||||||
|
boot.loader.systemd-boot.enable = true;
|
||||||
|
imports = [ self.inputs.disko.nixosModules.disko ];
|
||||||
|
disko.devices = {
|
||||||
|
disk = {
|
||||||
|
vdb = {
|
||||||
|
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";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
root = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "filesystem";
|
||||||
|
format = "ext4";
|
||||||
|
mountpoint = "/";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Example for a NixOS installer
|
||||||
|
|
||||||
|
```nix
|
||||||
|
# `self` here is referring to the flake `self`, you may need to pass it using `specialArgs` or define your NixOS installer configuration
|
||||||
|
# in the flake.nix itself to get direct access to the `self` flake variable.
|
||||||
|
{ pkgs, self, ... }:
|
||||||
|
let
|
||||||
|
dependencies = [
|
||||||
|
pkgs.stdenv.drvPath
|
||||||
|
self.nixosConfigurations.your-machine.config.system.build.toplevel
|
||||||
|
self.nixosConfigurations.your-machine.config.system.build.diskoScript
|
||||||
|
] ++ builtins.map (i: i.outPath) (builtins.attrValues self.inputs);
|
||||||
|
|
||||||
|
closureInfo = pkgs.closureInfo { rootPaths = dependencies; };
|
||||||
|
in
|
||||||
|
# Now add `closureInfo` to your NixOS installer
|
||||||
|
{
|
||||||
|
environment.etc."install-closure".source = "${closureInfo}/store-paths";
|
||||||
|
|
||||||
|
environment.systemPackages = [
|
||||||
|
(pkgs.writeShellScriptBin "install-nixos-unattended" ''
|
||||||
|
set -eux
|
||||||
|
# Replace "/dev/disk/by-id/some-disk-id" with your actual disk ID
|
||||||
|
exec ${pkgs.disko}/bin/disko-install --flake "${self}#your-machine" --disk vdb "/dev/disk/by-id/some-disk-id"
|
||||||
|
'')
|
||||||
|
];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Also see the [NixOS test of disko-install](https://github.com/nix-community/disko/blob/master/tests/disko-install/default.nix) that also runs without internet.
|
||||||
+11
-11
@@ -68,24 +68,24 @@ In Step 1, you chose a disk layout configuration from the
|
|||||||
and made a note of its URL.
|
and made a note of its URL.
|
||||||
|
|
||||||
Your configuration needs to be saved on the new machine for example
|
Your configuration needs to be saved on the new machine for example
|
||||||
as /tmp/disko-config.nix. You can do this using the `curl` command to download
|
as /tmp/disk-config.nix. You can do this using the `curl` command to download
|
||||||
from the url you noted above, using the `-o` option to save the file as
|
from the url you noted above, using the `-o` option to save the file as
|
||||||
disko-config.nix. Your commands would look like this if you had chosen the
|
disk-config.nix. Your commands would look like this if you had chosen the
|
||||||
hybrid layout:
|
hybrid layout:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
cd /tmp
|
cd /tmp
|
||||||
curl https://raw.githubusercontent.com/nix-community/disko/master/example/hybrid.nix -o /tmp/disko-config.nix
|
curl https://raw.githubusercontent.com/nix-community/disko/master/example/hybrid.nix -o /tmp/disk-config.nix
|
||||||
```
|
```
|
||||||
|
|
||||||
### Step 5: Adjust the device in the disk configuration
|
### Step 5: Adjust the device in the disk configuration
|
||||||
|
|
||||||
Inside the disko-config.nix the device needs to point to the correct disk name.
|
Inside the disk-config.nix the device needs to point to the correct disk name.
|
||||||
|
|
||||||
Open the configuration in your favorite editor i.e.:
|
Open the configuration in your favorite editor i.e.:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
nano /tmp/disko-config.nix
|
nano /tmp/disk-config.nix
|
||||||
```
|
```
|
||||||
|
|
||||||
Replace `<disk-name>` with the name of your disk obtained in Step 1.
|
Replace `<disk-name>` with the name of your disk obtained in Step 1.
|
||||||
@@ -107,7 +107,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.**
|
**Please note: This will erase any existing data on your disk.**
|
||||||
|
|
||||||
```console
|
```console
|
||||||
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko /tmp/disko-config.nix
|
sudo nix --experimental-features "nix-command flakes" run github:nix-community/disko -- --mode disko /tmp/disk-config.nix
|
||||||
```
|
```
|
||||||
|
|
||||||
After the command has run, your file system should have been formatted and
|
After the command has run, your file system should have been formatted and
|
||||||
@@ -131,13 +131,13 @@ the NixOS installation as described in the
|
|||||||
[NixOS manual](https://nixos.org/manual/nixos/stable/index.html#sec-installation) -
|
[NixOS manual](https://nixos.org/manual/nixos/stable/index.html#sec-installation) -
|
||||||
see the section headed "**Installing**", Steps 3 onwards. However, you will need
|
see the section headed "**Installing**", Steps 3 onwards. However, you will need
|
||||||
to include the partitioning and formatting configurations that you copied into
|
to include the partitioning and formatting configurations that you copied into
|
||||||
`/tmp/disko-config.nix` in your configuration, rather than allowing NixOS to
|
`/tmp/disk-config.nix` in your configuration, rather than allowing NixOS to
|
||||||
generate information about your file systems. When you are configuring the
|
generate information about your file systems. When you are configuring the
|
||||||
system as per Step 4 of the manual, you should:
|
system as per Step 4 of the manual, you should:
|
||||||
|
|
||||||
a) Include the `no-filesystems` switch when using the `nixos-generate-config`
|
a) Include the `no-filesystems` switch when using the `nixos-generate-config`
|
||||||
command to generate an initial `configuration.nix`. You will be supplying the
|
command to generate an initial `configuration.nix`. You will be supplying the
|
||||||
file system configuration details from `disko-config.nix`. Your CLI command to
|
file system configuration details from `disk-config.nix`. Your CLI command to
|
||||||
generate the configuration will be:
|
generate the configuration will be:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
@@ -149,7 +149,7 @@ This will create the file `configuration.nix` in `/mnt/etc/nixos`.
|
|||||||
b) Move the `disko` configuration to /etc/nixos
|
b) Move the `disko` configuration to /etc/nixos
|
||||||
|
|
||||||
```console
|
```console
|
||||||
mv /tmp/disko-config.nix /mnt/etc/nixos
|
mv /tmp/disk-config.nix /mnt/etc/nixos
|
||||||
```
|
```
|
||||||
|
|
||||||
c) You can now edit `configuration.nix` as per your requirements. This is
|
c) You can now edit `configuration.nix` as per your requirements. This is
|
||||||
@@ -163,7 +163,7 @@ NixOS configuration in the manual:
|
|||||||
[Example: NixOS Configuration](https://nixos.org/manual/nixos/stable/index.html#ex-config).
|
[Example: NixOS Configuration](https://nixos.org/manual/nixos/stable/index.html#ex-config).
|
||||||
|
|
||||||
d) When editing `configuration.nix`, you will need to add the `disko` NixOS
|
d) When editing `configuration.nix`, you will need to add the `disko` NixOS
|
||||||
module and `disko-config.nix` to the imports section. This section will already
|
module and `disk-config.nix` to the imports section. This section will already
|
||||||
include the file `./hardware-configuration.nix`, and you can add the new entries
|
include the file `./hardware-configuration.nix`, and you can add the new entries
|
||||||
just below this. This section will now include:
|
just below this. This section will now include:
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ imports =
|
|||||||
[ # Include the results of the hardware scan.
|
[ # Include the results of the hardware scan.
|
||||||
./hardware-configuration.nix
|
./hardware-configuration.nix
|
||||||
"${builtins.fetchTarball "https://github.com/nix-community/disko/archive/master.tar.gz"}/module.nix"
|
"${builtins.fetchTarball "https://github.com/nix-community/disko/archive/master.tar.gz"}/module.nix"
|
||||||
./disko-config.nix
|
./disk-config.nix
|
||||||
];
|
];
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
disko.devices = {
|
||||||
|
disk = {
|
||||||
|
vdb = {
|
||||||
|
type = "disk";
|
||||||
|
device = "/dev/disk/by-diskseq/1";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
ESP = {
|
||||||
|
priority = 1;
|
||||||
|
name = "ESP";
|
||||||
|
start = "1M";
|
||||||
|
end = "128M";
|
||||||
|
type = "EF00";
|
||||||
|
content = {
|
||||||
|
type = "filesystem";
|
||||||
|
format = "vfat";
|
||||||
|
mountpoint = "/boot";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
root = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "btrfs";
|
||||||
|
extraArgs = [ "-f" ]; # Override existing partition
|
||||||
|
mountpoint = "/";
|
||||||
|
mountOptions = [ "compress=zstd" "noatime" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
+1
-1
@@ -52,7 +52,7 @@
|
|||||||
"com.sun:auto-snapshot" = "false";
|
"com.sun:auto-snapshot" = "false";
|
||||||
};
|
};
|
||||||
mountpoint = "/";
|
mountpoint = "/";
|
||||||
postCreateHook = "zfs snapshot zroot@blank";
|
postCreateHook = "zfs list -t snapshot -H -o name | grep -E '^zroot@blank$' || zfs snapshot zroot@blank";
|
||||||
|
|
||||||
datasets = {
|
datasets = {
|
||||||
zfs_fs = {
|
zfs_fs = {
|
||||||
|
|||||||
Generated
+3
-3
@@ -2,11 +2,11 @@
|
|||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1710097495,
|
"lastModified": 1713687659,
|
||||||
"narHash": "sha256-B7Ea7q7hU7SE8wOPJ9oXEBjvB89yl2csaLjf5v/7jr8=",
|
"narHash": "sha256-Yd8KuOBpZ0Slau/NxFhMPJI0gBxeax0vq/FD0rqKwuQ=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "d40e866b1f98698d454dad8f592fe7616ff705a4",
|
"rev": "f2d7a289c5a5ece8521dd082b81ac7e4a57c2c5c",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
+48
-31
@@ -1,41 +1,58 @@
|
|||||||
{ flake
|
{
|
||||||
, flakeAttr
|
flake,
|
||||||
, diskMappings
|
flakeAttr,
|
||||||
, writeEfiBootEntries ? false
|
diskMappings,
|
||||||
, rootMountPoint ? "/mnt"
|
writeEfiBootEntries ? false,
|
||||||
|
rootMountPoint ? "/mnt",
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
originalSystem = (builtins.getFlake "${flake}").nixosConfigurations."${flakeAttr}";
|
originalSystem = (builtins.getFlake "${flake}").nixosConfigurations."${flakeAttr}";
|
||||||
diskoSystem =
|
lib = originalSystem.pkgs.lib;
|
||||||
|
|
||||||
|
deviceName =
|
||||||
|
name:
|
||||||
|
if diskMappings ? ${name} then
|
||||||
|
diskMappings.${name}
|
||||||
|
else
|
||||||
|
throw "No device passed for disk '${name}'. Pass `--disk ${name} /dev/name` via commandline";
|
||||||
|
|
||||||
|
modifiedDisks = builtins.mapAttrs (
|
||||||
|
name: value:
|
||||||
let
|
let
|
||||||
lib = originalSystem.lib;
|
dev = deviceName name;
|
||||||
|
|
||||||
modifiedDisks = builtins.mapAttrs
|
|
||||||
(name: value: let
|
|
||||||
dev = if diskMappings ? ${name} then
|
|
||||||
diskMappings.${name}
|
|
||||||
else
|
|
||||||
throw "No device passed for disk '${name}'. Pass `--disk ${name} /dev/name` via commandline";
|
|
||||||
in value // {
|
|
||||||
device = dev;
|
|
||||||
content = value.content // { device = dev; };
|
|
||||||
})
|
|
||||||
originalSystem.config.disko.devices.disk;
|
|
||||||
|
|
||||||
cleanedDisks = lib.filterAttrsRecursive (n: _: !lib.hasPrefix "_" n) modifiedDisks;
|
|
||||||
in
|
in
|
||||||
originalSystem.extendModules {
|
value
|
||||||
modules = [{
|
// {
|
||||||
|
device = dev;
|
||||||
|
content = value.content // {
|
||||||
|
device = dev;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
) originalSystem.config.disko.devices.disk;
|
||||||
|
|
||||||
|
# filter all nixos module internal attributes
|
||||||
|
cleanedDisks = lib.filterAttrsRecursive (n: _: !lib.hasPrefix "_" n) modifiedDisks;
|
||||||
|
|
||||||
|
diskoSystem = originalSystem.extendModules {
|
||||||
|
modules = [
|
||||||
|
{
|
||||||
disko.rootMountPoint = rootMountPoint;
|
disko.rootMountPoint = rootMountPoint;
|
||||||
disko.devices.disk = lib.mkVMOverride cleanedDisks;
|
disko.devices.disk = lib.mkVMOverride cleanedDisks;
|
||||||
}];
|
}
|
||||||
};
|
];
|
||||||
installSystem = originalSystem.extendModules {
|
};
|
||||||
modules = [({ lib, ... }: {
|
|
||||||
boot.loader.efi.canTouchEfiVariables = lib.mkVMOverride writeEfiBootEntries;
|
installSystem = originalSystem.extendModules {
|
||||||
boot.loader.grub.devices = lib.mkVMOverride diskoSystem.config.boot.loader.grub.devices;
|
modules = [
|
||||||
})];
|
(
|
||||||
};
|
{ lib, ... }:
|
||||||
|
{
|
||||||
|
boot.loader.efi.canTouchEfiVariables = lib.mkVMOverride writeEfiBootEntries;
|
||||||
|
boot.loader.grub.devices = lib.mkVMOverride diskoSystem.config.boot.loader.grub.devices;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
];
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
installToplevel = installSystem.config.system.build.toplevel;
|
installToplevel = installSystem.config.system.build.toplevel;
|
||||||
|
|||||||
+2
-1
@@ -400,6 +400,7 @@ let
|
|||||||
lvm2
|
lvm2
|
||||||
bash
|
bash
|
||||||
jq
|
jq
|
||||||
|
gnused
|
||||||
])}:$PATH
|
])}:$PATH
|
||||||
${cfg.config._destroy}
|
${cfg.config._destroy}
|
||||||
'';
|
'';
|
||||||
@@ -448,7 +449,7 @@ let
|
|||||||
|
|
||||||
# shellcheck disable=SC2043
|
# shellcheck disable=SC2043
|
||||||
for dev in ${toString (lib.catAttrs "device" (lib.attrValues devices.disk))}; do
|
for dev in ${toString (lib.catAttrs "device" (lib.attrValues devices.disk))}; do
|
||||||
${../disk-deactivate}/disk-deactivate "$dev"
|
$BASH ${../disk-deactivate}/disk-deactivate "$dev"
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|||||||
+10
-2
@@ -243,15 +243,23 @@ let
|
|||||||
# running direct mode
|
# running direct mode
|
||||||
machine.succeed("${tsp-format}")
|
machine.succeed("${tsp-format}")
|
||||||
machine.succeed("${tsp-mount}")
|
machine.succeed("${tsp-mount}")
|
||||||
machine.succeed("${tsp-mount}") # verify that the command is idempotent
|
machine.succeed("${tsp-mount}") # verify that mount is idempotent
|
||||||
machine.succeed("${tsp-disko}") # verify that we can destroy and recreate
|
machine.succeed("${tsp-disko}") # 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("test -e /mnt/home/testfile")
|
||||||
''}
|
''}
|
||||||
${lib.optionalString (testMode == "module") ''
|
${lib.optionalString (testMode == "module") ''
|
||||||
# running module mode
|
# running module mode
|
||||||
machine.succeed("${nodes.machine.system.build.formatScript}")
|
machine.succeed("${nodes.machine.system.build.formatScript}")
|
||||||
machine.succeed("${nodes.machine.system.build.mountScript}")
|
machine.succeed("${nodes.machine.system.build.mountScript}")
|
||||||
machine.succeed("${nodes.machine.system.build.mountScript}") # verify that the command is idempotent
|
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("${nodes.machine.system.build.diskoScript}") # 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("test -e /mnt/home/testfile")
|
||||||
''}
|
''}
|
||||||
|
|
||||||
${postDisko}
|
${postDisko}
|
||||||
|
|||||||
+34
-21
@@ -31,7 +31,11 @@ let
|
|||||||
swapCreate = mountpoint: swap:
|
swapCreate = mountpoint: swap:
|
||||||
lib.concatMapStringsSep
|
lib.concatMapStringsSep
|
||||||
"\n"
|
"\n"
|
||||||
(file: ''btrfs filesystem mkswapfile --size ${file.size} "${mountpoint}/${file.path}"'')
|
(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
|
in
|
||||||
@@ -112,26 +116,35 @@ in
|
|||||||
_create = diskoLib.mkCreateOption {
|
_create = diskoLib.mkCreateOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = ''
|
default = ''
|
||||||
mkfs.btrfs ${config.device} ${toString config.extraArgs}
|
# create the filesystem only if the device seems empty
|
||||||
${lib.optionalString (config.swap != {}) ''
|
if ! (blkid '${config.device}' -o export | grep -q '^TYPE='); then
|
||||||
(
|
mkfs.btrfs "${config.device}" ${toString config.extraArgs}
|
||||||
MNTPOINT=$(mktemp -d)
|
fi
|
||||||
mount ${device} "$MNTPOINT" -o subvol=/
|
${lib.optionalString (config.swap != {} || config.subvolumes != {}) ''
|
||||||
trap 'umount $MNTPOINT; rm -rf $MNTPOINT' EXIT
|
if (blkid "${config.device}" -o export | grep -q '^TYPE=btrfs$'); then
|
||||||
${swapCreate "$MNTPOINT" config.swap}
|
${lib.optionalString (config.swap != {}) ''
|
||||||
)
|
(
|
||||||
|
MNTPOINT=$(mktemp -d)
|
||||||
|
mount ${device} "$MNTPOINT" -o subvol=/
|
||||||
|
trap 'umount $MNTPOINT; rm -rf $MNTPOINT' EXIT
|
||||||
|
${swapCreate "$MNTPOINT" config.swap}
|
||||||
|
)
|
||||||
|
''}
|
||||||
|
${lib.concatMapStrings (subvol: ''
|
||||||
|
(
|
||||||
|
MNTPOINT=$(mktemp -d)
|
||||||
|
mount ${config.device} "$MNTPOINT" -o subvol=/
|
||||||
|
trap 'umount $MNTPOINT; rm -rf $MNTPOINT' EXIT
|
||||||
|
SUBVOL_ABS_PATH="$MNTPOINT/${subvol.name}"
|
||||||
|
mkdir -p "$(dirname "$SUBVOL_ABS_PATH")"
|
||||||
|
if ! btrfs subvolume show "$SUBVOL_ABS_PATH" > /dev/null 2>&1; then
|
||||||
|
btrfs subvolume create "$SUBVOL_ABS_PATH" ${toString subvol.extraArgs}
|
||||||
|
fi
|
||||||
|
${swapCreate "$SUBVOL_ABS_PATH" subvol.swap}
|
||||||
|
)
|
||||||
|
'') (lib.attrValues config.subvolumes)}
|
||||||
|
fi
|
||||||
''}
|
''}
|
||||||
${lib.concatMapStrings (subvol: ''
|
|
||||||
(
|
|
||||||
MNTPOINT=$(mktemp -d)
|
|
||||||
mount ${config.device} "$MNTPOINT" -o subvol=/
|
|
||||||
trap 'umount $MNTPOINT; rm -rf $MNTPOINT' EXIT
|
|
||||||
SUBVOL_ABS_PATH="$MNTPOINT/${subvol.name}"
|
|
||||||
mkdir -p "$(dirname "$SUBVOL_ABS_PATH")"
|
|
||||||
btrfs subvolume create "$SUBVOL_ABS_PATH" ${toString subvol.extraArgs}
|
|
||||||
${swapCreate "$SUBVOL_ABS_PATH" subvol.swap}
|
|
||||||
)
|
|
||||||
'') (lib.attrValues config.subvolumes)}
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = diskoLib.mkMountOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
@@ -206,7 +219,7 @@ in
|
|||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||||
default = pkgs:
|
default = pkgs:
|
||||||
[ pkgs.btrfs-progs pkgs.coreutils ];
|
[ pkgs.btrfs-progs pkgs.coreutils pkgs.gnugrep ];
|
||||||
description = "Packages";
|
description = "Packages";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -44,9 +44,11 @@
|
|||||||
_create = diskoLib.mkCreateOption {
|
_create = diskoLib.mkCreateOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = ''
|
default = ''
|
||||||
mkfs.${config.format} \
|
if ! (blkid '${config.device}' | grep -q 'TYPE='); then
|
||||||
${toString config.extraArgs} \
|
mkfs.${config.format} \
|
||||||
${config.device}
|
${toString config.extraArgs} \
|
||||||
|
${config.device}
|
||||||
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = diskoLib.mkMountOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
@@ -79,11 +81,12 @@
|
|||||||
readOnly = true;
|
readOnly = true;
|
||||||
# type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
# type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||||
default = pkgs:
|
default = pkgs:
|
||||||
[ pkgs.util-linux ] ++ (
|
[ pkgs.util-linux pkgs.gnugrep ] ++ (
|
||||||
# TODO add many more
|
# TODO add many more
|
||||||
if (config.format == "xfs") then [ pkgs.xfsprogs ]
|
if (config.format == "xfs") then [ pkgs.xfsprogs ]
|
||||||
else if (config.format == "btrfs") then [ pkgs.btrfs-progs ]
|
else if (config.format == "btrfs") then [ pkgs.btrfs-progs ]
|
||||||
else if (config.format == "vfat") then [ pkgs.dosfstools ]
|
else if (config.format == "vfat") then [ pkgs.dosfstools ]
|
||||||
|
else if (config.format == "exfat") then [ pkgs.exfat ]
|
||||||
else if (config.format == "ext2") then [ pkgs.e2fsprogs ]
|
else if (config.format == "ext2") then [ pkgs.e2fsprogs ]
|
||||||
else if (config.format == "ext3") then [ pkgs.e2fsprogs ]
|
else if (config.format == "ext3") then [ pkgs.e2fsprogs ]
|
||||||
else if (config.format == "ext4") then [ pkgs.e2fsprogs ]
|
else if (config.format == "ext4") then [ pkgs.e2fsprogs ]
|
||||||
|
|||||||
+22
-5
@@ -74,6 +74,11 @@ in
|
|||||||
can be 100% for the whole remaining disk, will be done last in that case.
|
can be 100% for the whole remaining disk, will be done last in that case.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
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;
|
||||||
|
description = "Alignment of the partition, if sectors are used as start or end it can be aligned to 1";
|
||||||
|
};
|
||||||
start = lib.mkOption {
|
start = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = "0";
|
default = "0";
|
||||||
@@ -153,18 +158,26 @@ in
|
|||||||
_create = diskoLib.mkCreateOption {
|
_create = diskoLib.mkCreateOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = ''
|
default = ''
|
||||||
|
if ! blkid "${config.device}" >&2; then
|
||||||
|
sgdisk --clear ${config.device}
|
||||||
|
fi
|
||||||
${lib.concatStrings (map (partition: ''
|
${lib.concatStrings (map (partition: ''
|
||||||
sgdisk \
|
# try to create the partition, if it fails, try to change the type and name
|
||||||
--align-end \
|
if ! sgdisk \
|
||||||
|
--align-end ${lib.optionalString (partition.alignment != 0) ''--set-alignment=${builtins.toString partition.alignment}''} \
|
||||||
--new=${toString partition._index}:${partition.start}:${partition.end} \
|
--new=${toString partition._index}:${partition.start}:${partition.end} \
|
||||||
--change-name=${toString partition._index}:${partition.label} \
|
--change-name=${toString partition._index}:${partition.label} \
|
||||||
--typecode=${toString partition._index}:${partition.type} \
|
--typecode=${toString partition._index}:${partition.type} \
|
||||||
${config.device}
|
${config.device}
|
||||||
|
then sgdisk \
|
||||||
|
--change-name=${toString partition._index}:${partition.label} \
|
||||||
|
--typecode=${toString partition._index}:${partition.type} \
|
||||||
|
${config.device}
|
||||||
|
fi
|
||||||
# ensure /dev/disk/by-path/..-partN exists before continuing
|
# ensure /dev/disk/by-path/..-partN exists before continuing
|
||||||
partprobe ${config.device}
|
partprobe ${config.device} || : # sometimes partprobe fails, but the partitions are still up2date
|
||||||
udevadm trigger --subsystem-match=block
|
udevadm trigger --subsystem-match=block
|
||||||
udevadm settle
|
udevadm settle
|
||||||
${lib.optionalString (partition.content != null) partition.content._create}
|
|
||||||
'') sortedPartitions)}
|
'') sortedPartitions)}
|
||||||
|
|
||||||
${
|
${
|
||||||
@@ -179,8 +192,12 @@ in
|
|||||||
${lib.concatMapStrings (p:
|
${lib.concatMapStrings (p:
|
||||||
p.hybrid._create
|
p.hybrid._create
|
||||||
)
|
)
|
||||||
sortedHybridPartitions}
|
sortedHybridPartitions
|
||||||
|
}
|
||||||
|
|
||||||
|
${lib.concatStrings (map (partition: ''
|
||||||
|
${lib.optionalString (partition.content != null) partition.content._create}
|
||||||
|
'') sortedPartitions)}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = diskoLib.mkMountOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
|
|||||||
+23
-21
@@ -112,26 +112,28 @@ in
|
|||||||
_create = diskoLib.mkCreateOption {
|
_create = diskoLib.mkCreateOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = ''
|
default = ''
|
||||||
${lib.optionalString config.askPassword ''
|
if ! blkid "${config.device}" >/dev/null || ! (blkid "${config.device}" -o export | grep -q '^TYPE='); then
|
||||||
set +x
|
${lib.optionalString config.askPassword ''
|
||||||
askPassword() {
|
set +x
|
||||||
echo "Enter password for ${config.device}: "
|
askPassword() {
|
||||||
IFS= read -r -s password
|
echo "Enter password for ${config.device}: "
|
||||||
echo "Enter password for ${config.device} again to be safe: "
|
IFS= read -r -s password
|
||||||
IFS= read -r -s password_check
|
echo "Enter password for ${config.device} again to be safe: "
|
||||||
export password
|
IFS= read -r -s password_check
|
||||||
[ "$password" = "$password_check" ]
|
export password
|
||||||
}
|
[ "$password" = "$password_check" ]
|
||||||
until askPassword; do
|
}
|
||||||
echo "Passwords did not match, please try again."
|
until askPassword; do
|
||||||
done
|
echo "Passwords did not match, please try again."
|
||||||
set -x
|
done
|
||||||
''}
|
set -x
|
||||||
cryptsetup -q luksFormat ${config.device} ${toString config.extraFormatArgs} ${keyFileArgs}
|
''}
|
||||||
${cryptsetupOpen} --persistent
|
cryptsetup -q luksFormat ${config.device} ${toString config.extraFormatArgs} ${keyFileArgs}
|
||||||
${toString (lib.forEach config.additionalKeyFiles (keyFile: ''
|
${cryptsetupOpen} --persistent
|
||||||
cryptsetup luksAddKey ${config.device} ${keyFile} ${keyFileArgs}
|
${toString (lib.forEach config.additionalKeyFiles (keyFile: ''
|
||||||
''))}
|
cryptsetup luksAddKey ${config.device} ${keyFile} ${keyFileArgs}
|
||||||
|
''))}
|
||||||
|
fi
|
||||||
${lib.optionalString (config.content != null) config.content._create}
|
${lib.optionalString (config.content != null) config.content._create}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
@@ -176,7 +178,7 @@ in
|
|||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||||
default = pkgs: [ 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";
|
description = "Packages";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,7 +31,9 @@
|
|||||||
_create = diskoLib.mkCreateOption {
|
_create = diskoLib.mkCreateOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = ''
|
default = ''
|
||||||
pvcreate ${config.device}
|
if ! (blkid '${config.device}' | grep -q 'TYPE='); then
|
||||||
|
pvcreate ${config.device}
|
||||||
|
fi
|
||||||
echo "${config.device}" >>"$disko_devices_dir"/lvm_${config.vg}
|
echo "${config.device}" >>"$disko_devices_dir"/lvm_${config.vg}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
@@ -49,7 +51,7 @@
|
|||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||||
default = pkgs: [ pkgs.lvm2 ];
|
default = pkgs: [ pkgs.gnugrep pkgs.lvm2 ];
|
||||||
description = "Packages";
|
description = "Packages";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
+16
-9
@@ -68,16 +68,23 @@
|
|||||||
in
|
in
|
||||||
''
|
''
|
||||||
readarray -t lvm_devices < <(cat "$disko_devices_dir"/lvm_${config.name})
|
readarray -t lvm_devices < <(cat "$disko_devices_dir"/lvm_${config.name})
|
||||||
vgcreate ${config.name} \
|
if ! vgdisplay "${config.name}" >/dev/null; then
|
||||||
"''${lvm_devices[@]}"
|
vgcreate ${config.name} \
|
||||||
|
"''${lvm_devices[@]}"
|
||||||
|
fi
|
||||||
|
${lib.concatMapStrings (lv: ''
|
||||||
|
if ! lvdisplay '${config.name}/${lv.name}'; then
|
||||||
|
lvcreate \
|
||||||
|
--yes \
|
||||||
|
${if lib.hasInfix "%" lv.size then "-l" else "-L"} ${lv.size} \
|
||||||
|
-n ${lv.name} \
|
||||||
|
${lib.optionalString (lv.lvm_type != null) "--type=${lv.lvm_type}"} \
|
||||||
|
${toString lv.extraArgs} \
|
||||||
|
${config.name}
|
||||||
|
fi
|
||||||
|
'') sortedLvs}
|
||||||
|
|
||||||
${lib.concatMapStrings (lv: ''
|
${lib.concatMapStrings (lv: ''
|
||||||
lvcreate \
|
|
||||||
--yes \
|
|
||||||
${if lib.hasInfix "%" lv.size then "-l" else "-L"} ${lv.size} \
|
|
||||||
-n ${lv.name} \
|
|
||||||
${lib.optionalString (lv.lvm_type != null) "--type=${lv.lvm_type}"} \
|
|
||||||
${toString lv.extraArgs} \
|
|
||||||
${config.name}
|
|
||||||
${lib.optionalString (lv.content != null) lv.content._create}
|
${lib.optionalString (lv.content != null) lv.content._create}
|
||||||
'') sortedLvs}
|
'') sortedLvs}
|
||||||
'';
|
'';
|
||||||
|
|||||||
+15
-13
@@ -34,19 +34,21 @@
|
|||||||
_create = diskoLib.mkCreateOption {
|
_create = diskoLib.mkCreateOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = ''
|
default = ''
|
||||||
readarray -t disk_devices < <(cat "$disko_devices_dir"/raid_${config.name})
|
if ! test -e /dev/md/${config.name}; then
|
||||||
echo 'y' | mdadm --create /dev/md/${config.name} \
|
readarray -t disk_devices < <(cat "$disko_devices_dir"/raid_${config.name})
|
||||||
--level=${toString config.level} \
|
echo 'y' | mdadm --create /dev/md/${config.name} \
|
||||||
--raid-devices="$(wc -l "$disko_devices_dir"/raid_${config.name} | cut -f 1 -d " ")" \
|
--level=${toString config.level} \
|
||||||
--metadata=${config.metadata} \
|
--raid-devices="$(wc -l "$disko_devices_dir"/raid_${config.name} | cut -f 1 -d " ")" \
|
||||||
--force \
|
--metadata=${config.metadata} \
|
||||||
--homehost=any \
|
--force \
|
||||||
"''${disk_devices[@]}"
|
--homehost=any \
|
||||||
partprobe /dev/md/${config.name}
|
"''${disk_devices[@]}"
|
||||||
udevadm trigger --subsystem-match=block
|
udevadm trigger --subsystem-match=block
|
||||||
udevadm settle
|
udevadm settle
|
||||||
# for some reason mdadm devices spawn with an existing partition table, so we need to wipe it
|
# for some reason mdadm devices spawn with an existing partition table, so we need to wipe it
|
||||||
sgdisk --zap-all /dev/md/${config.name}
|
sgdisk --zap-all /dev/md/${config.name}
|
||||||
|
partprobe /dev/md/${config.name}
|
||||||
|
fi
|
||||||
${lib.optionalString (config.content != null) config.content._create}
|
${lib.optionalString (config.content != null) config.content._create}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|||||||
+5
-3
@@ -40,9 +40,11 @@
|
|||||||
_create = diskoLib.mkCreateOption {
|
_create = diskoLib.mkCreateOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = ''
|
default = ''
|
||||||
mkswap \
|
if ! blkid "${config.device}" -o export | grep -q '^TYPE='; then
|
||||||
${toString config.extraArgs} \
|
mkswap \
|
||||||
${config.device}
|
${toString config.extraArgs} \
|
||||||
|
${config.device}
|
||||||
|
fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
_mount = diskoLib.mkMountOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
|
|||||||
+25
-21
@@ -88,28 +88,32 @@
|
|||||||
_create = diskoLib.mkCreateOption {
|
_create = diskoLib.mkCreateOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = ''
|
default = ''
|
||||||
parted -s ${config.device} -- mklabel ${config.format}
|
if ! blkid "${config.device}" >/dev/null; then
|
||||||
|
parted -s ${config.device} -- mklabel ${config.format}
|
||||||
|
${lib.concatStrings (map (partition: ''
|
||||||
|
${lib.optionalString (config.format == "gpt") ''
|
||||||
|
parted -s ${config.device} -- mkpart ${partition.name} ${diskoLib.maybeStr partition.fs-type} ${partition.start} ${partition.end}
|
||||||
|
''}
|
||||||
|
${lib.optionalString (config.format == "msdos") ''
|
||||||
|
parted -s ${config.device} -- mkpart ${partition.part-type} ${diskoLib.maybeStr partition.fs-type} ${partition.start} ${partition.end}
|
||||||
|
''}
|
||||||
|
# ensure /dev/disk/by-path/..-partN exists before continuing
|
||||||
|
partprobe ${config.device}
|
||||||
|
udevadm trigger --subsystem-match=block
|
||||||
|
udevadm settle
|
||||||
|
${lib.optionalString partition.bootable ''
|
||||||
|
parted -s ${config.device} -- set ${toString partition._index} boot on
|
||||||
|
''}
|
||||||
|
${lib.concatMapStringsSep "" (flag: ''
|
||||||
|
parted -s ${config.device} -- set ${toString partition._index} ${flag} on
|
||||||
|
'') partition.flags}
|
||||||
|
# ensure further operations can detect new partitions
|
||||||
|
partprobe ${config.device}
|
||||||
|
udevadm trigger --subsystem-match=block
|
||||||
|
udevadm settle
|
||||||
|
'') config.partitions)}
|
||||||
|
fi
|
||||||
${lib.concatStrings (map (partition: ''
|
${lib.concatStrings (map (partition: ''
|
||||||
${lib.optionalString (config.format == "gpt") ''
|
|
||||||
parted -s ${config.device} -- mkpart ${partition.name} ${diskoLib.maybeStr partition.fs-type} ${partition.start} ${partition.end}
|
|
||||||
''}
|
|
||||||
${lib.optionalString (config.format == "msdos") ''
|
|
||||||
parted -s ${config.device} -- mkpart ${partition.part-type} ${diskoLib.maybeStr partition.fs-type} ${partition.start} ${partition.end}
|
|
||||||
''}
|
|
||||||
# ensure /dev/disk/by-path/..-partN exists before continuing
|
|
||||||
partprobe ${config.device}
|
|
||||||
udevadm trigger --subsystem-match=block
|
|
||||||
udevadm settle
|
|
||||||
${lib.optionalString partition.bootable ''
|
|
||||||
parted -s ${config.device} -- set ${toString partition._index} boot on
|
|
||||||
''}
|
|
||||||
${lib.concatMapStringsSep "" (flag: ''
|
|
||||||
parted -s ${config.device} -- set ${toString partition._index} ${flag} on
|
|
||||||
'') partition.flags}
|
|
||||||
# ensure further operations can detect new partitions
|
|
||||||
partprobe ${config.device}
|
|
||||||
udevadm trigger --subsystem-match=block
|
|
||||||
udevadm settle
|
|
||||||
${lib.optionalString (partition.content != null) partition.content._create}
|
${lib.optionalString (partition.content != null) partition.content._create}
|
||||||
'') config.partitions)}
|
'') config.partitions)}
|
||||||
'';
|
'';
|
||||||
|
|||||||
@@ -59,8 +59,10 @@
|
|||||||
# since (create order != mount order)
|
# since (create order != mount order)
|
||||||
# -p creates parents automatically
|
# -p creates parents automatically
|
||||||
default = ''
|
default = ''
|
||||||
zfs create -up ${config._name} \
|
if ! zfs get type ${config._name} >/dev/null 2>&1; then
|
||||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)}
|
zfs create -up ${config._name} \
|
||||||
|
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)}
|
||||||
|
fi
|
||||||
'';
|
'';
|
||||||
} // { readOnly = false; };
|
} // { readOnly = false; };
|
||||||
|
|
||||||
|
|||||||
@@ -47,13 +47,15 @@
|
|||||||
_create = diskoLib.mkCreateOption {
|
_create = diskoLib.mkCreateOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = ''
|
default = ''
|
||||||
zfs create ${config._parent.name}/${config.name} \
|
if ! zfs get type ${config._parent.name}/${config.name} >/dev/null 2>&1; then
|
||||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
|
zfs create ${config._parent.name}/${config.name} \
|
||||||
-V ${config.size}
|
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
|
||||||
zvol_wait
|
-V ${config.size}
|
||||||
partprobe /dev/zvol/${config._parent.name}/${config.name}
|
zvol_wait
|
||||||
udevadm trigger --subsystem-match=block
|
partprobe /dev/zvol/${config._parent.name}/${config.name}
|
||||||
udevadm settle
|
udevadm trigger --subsystem-match=block
|
||||||
|
udevadm settle
|
||||||
|
fi
|
||||||
${lib.optionalString (config.content != null) config.content._create}
|
${lib.optionalString (config.content != null) config.content._create}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|||||||
+30
-8
@@ -62,13 +62,35 @@
|
|||||||
inherit config options;
|
inherit config options;
|
||||||
default = ''
|
default = ''
|
||||||
readarray -t zfs_devices < <(cat "$disko_devices_dir"/zfs_${config.name})
|
readarray -t zfs_devices < <(cat "$disko_devices_dir"/zfs_${config.name})
|
||||||
zpool create -f ${config.name} \
|
if zpool list '${config.name}'; then
|
||||||
-R ${rootMountPoint} ${config.mode} \
|
echo "not creating zpool ${config.name} as a pool with that name already exists" >&2
|
||||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
|
else
|
||||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \
|
continue=1
|
||||||
"''${zfs_devices[@]}"
|
for dev in "''${zfs_devices[@]}"; do
|
||||||
if [[ $(zfs get -H mounted ${config.name} | cut -f3) == "yes" ]]; then
|
if ! blkid "$dev" >/dev/null; then
|
||||||
zfs unmount ${config.name}
|
# blkid fails, so device seems empty
|
||||||
|
:
|
||||||
|
elif (blkid "$dev" -o export | grep '^PTUUID='); then
|
||||||
|
echo "device $dev already has a partuuid, skipping creating zpool ${config.name}" >&2
|
||||||
|
continue=0
|
||||||
|
elif (blkid "$dev" -o export | grep '^TYPE=zfs_member'); then
|
||||||
|
# zfs_member is a zfs partition, so we try to add the device to the pool
|
||||||
|
:
|
||||||
|
elif (blkid "$dev" -o export | grep '^TYPE='); then
|
||||||
|
echo "device $dev already has a partition, skipping creating zpool ${config.name}" >&2
|
||||||
|
continue=0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ $continue -eq 1 ]; then
|
||||||
|
zpool create -f ${config.name} \
|
||||||
|
-R ${rootMountPoint} ${config.mode} \
|
||||||
|
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
|
||||||
|
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \
|
||||||
|
"''${zfs_devices[@]}"
|
||||||
|
if [[ $(zfs get -H mounted ${config.name} | cut -f3) == "yes" ]]; then
|
||||||
|
zfs unmount ${config.name}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
${lib.concatMapStrings (dataset: dataset._create) (lib.attrValues config.datasets)}
|
${lib.concatMapStrings (dataset: dataset._create) (lib.attrValues config.datasets)}
|
||||||
'';
|
'';
|
||||||
@@ -98,7 +120,7 @@
|
|||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
type = lib.types.functionTo (lib.types.listOf lib.types.package);
|
||||||
default = pkgs: [ 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";
|
description = "Packages";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{ pkgs ? import <nixpkgs> { }
|
||||||
|
, diskoLib ? pkgs.callPackage ../lib { }
|
||||||
|
}:
|
||||||
|
diskoLib.testLib.makeDiskoTest {
|
||||||
|
inherit pkgs;
|
||||||
|
name = "btrfs-only-root-subvolume";
|
||||||
|
disko-config = ../example/btrfs-only-root-subvolume.nix;
|
||||||
|
extraTestScript = ''
|
||||||
|
machine.succeed("btrfs subvolume list /");
|
||||||
|
'';
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ diskoLib.makeDiskImages {
|
|||||||
({ config, ... }: {
|
({ config, ... }: {
|
||||||
documentation.enable = false;
|
documentation.enable = false;
|
||||||
system.stateVersion = config.system.nixos.version;
|
system.stateVersion = config.system.nixos.version;
|
||||||
|
disko.memSize = 2048;
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user