mirror of
https://github.com/nix-community/disko.git
synced 2026-12-01 21:43:29 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aef9a509db | ||
|
|
59f915b45a | ||
|
|
f772d2045e | ||
|
|
ce3b896151 | ||
|
|
2791cedcba | ||
|
|
583bdf4fc6 | ||
|
|
0ce1b15b99 | ||
|
|
1b19111387 | ||
|
|
44e97d4197 | ||
|
|
6095c996e1 | ||
|
|
2077e9cef2 | ||
|
|
b814f6b555 | ||
|
|
7d6561fee4 | ||
|
|
2890a8c922 | ||
|
|
a050895e4e | ||
|
|
e526d4e653 | ||
|
|
db6cbcadfe |
No files matched your search
@@ -57,11 +57,11 @@ To access sample configurations for commonly-used disk layouts, refer to the
|
|||||||
|
|
||||||
A simple disko configuration may look like this:
|
A simple disko configuration may look like this:
|
||||||
|
|
||||||
```
|
```nix
|
||||||
{
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
my-disk = {
|
||||||
device = "/dev/sda";
|
device = "/dev/sda";
|
||||||
type = "disk";
|
type = "disk";
|
||||||
content = {
|
content = {
|
||||||
@@ -95,8 +95,8 @@ If you'd saved this configuration in /tmp/disko-config.nix, and wanted to create
|
|||||||
a disk named /dev/nvme0n1, you would run the following command to partition,
|
a disk named /dev/nvme0n1, you would run the following command to partition,
|
||||||
format and mount the disk.
|
format and mount the disk.
|
||||||
|
|
||||||
```
|
```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/disko-config.nix
|
||||||
```
|
```
|
||||||
|
|
||||||
## Related Tools
|
## Related Tools
|
||||||
|
|||||||
+3
-3
@@ -46,7 +46,7 @@ If you use nix flakes support:
|
|||||||
First add it to [niv](https://github.com/nmattia/niv):
|
First add it to [niv](https://github.com/nmattia/niv):
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ niv add nix-community/disko
|
niv add nix-community/disko
|
||||||
```
|
```
|
||||||
|
|
||||||
Then add the following to your configuration.nix in the `imports` list:
|
Then add the following to your configuration.nix in the `imports` list:
|
||||||
@@ -64,8 +64,8 @@ Then add the following to your configuration.nix in the `imports` list:
|
|||||||
As root run:
|
As root run:
|
||||||
|
|
||||||
```console
|
```console
|
||||||
$ nix-channel --add https://github.com/nix-community/disko/archive/master.tar.gz disko
|
nix-channel --add https://github.com/nix-community/disko/archive/master.tar.gz disko
|
||||||
$ nix-channel --update
|
nix-channel --update
|
||||||
```
|
```
|
||||||
|
|
||||||
Then add the following to your configuration.nix in the `imports` list:
|
Then add the following to your configuration.nix in the `imports` list:
|
||||||
|
|||||||
+22
-23
@@ -47,8 +47,8 @@ the NixOS manual. Boot the machine from this USB drive.
|
|||||||
|
|
||||||
Identify the name of your system disk by using the `lsblk` command as follows:
|
Identify the name of your system disk by using the `lsblk` command as follows:
|
||||||
|
|
||||||
```
|
```console
|
||||||
$ lsblk
|
lsblk
|
||||||
```
|
```
|
||||||
|
|
||||||
The output from this command will look something like this:
|
The output from this command will look something like this:
|
||||||
@@ -73,9 +73,9 @@ 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
|
disko-config.nix. Your commands would look like this if you had chosen the
|
||||||
hybrid layout:
|
hybrid layout:
|
||||||
|
|
||||||
```
|
```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/disko-config.nix
|
||||||
```
|
```
|
||||||
|
|
||||||
### Step 5: Adjust the device in the disk configuration
|
### Step 5: Adjust the device in the disk configuration
|
||||||
@@ -84,20 +84,20 @@ Inside the disko-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
|
||||||
nano /tmp/disko-config.nix
|
nano /tmp/disko-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.
|
||||||
|
|
||||||
```
|
```nix
|
||||||
...
|
# ...
|
||||||
main = {
|
main = {
|
||||||
type = "disk";
|
type = "disk";
|
||||||
device = "<disk-name>";
|
device = "<disk-name>";
|
||||||
content = {
|
content = {
|
||||||
type = "gpt";
|
type = "gpt";
|
||||||
...
|
# ...
|
||||||
```
|
```
|
||||||
|
|
||||||
### Step 6: Run disko to partition, format and mount your disks
|
### Step 6: Run disko to partition, format and mount your disks
|
||||||
@@ -106,16 +106,15 @@ 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
|
||||||
|
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/disko-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
|
||||||
mounted. You can verify this by running the following command:
|
mounted. You can verify this by running the following command:
|
||||||
|
|
||||||
```
|
```console
|
||||||
$ mount | grep /mnt
|
mount | grep /mnt
|
||||||
```
|
```
|
||||||
|
|
||||||
The output should look like this if your disk name is `nvme0n1`.
|
The output should look like this if your disk name is `nvme0n1`.
|
||||||
@@ -141,16 +140,16 @@ 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 `disko-config.nix`. Your CLI command to
|
||||||
generate the configuration will be:
|
generate the configuration will be:
|
||||||
|
|
||||||
```
|
```console
|
||||||
$ nixos-generate-config --no-filesystems --root /mnt
|
nixos-generate-config --no-filesystems --root /mnt
|
||||||
```
|
```
|
||||||
|
|
||||||
This will create the file `configuration.nix` in `/mnt/etc/nixos`.
|
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
|
||||||
$ mv /tmp/disko-config.nix /mnt/etc/nixos
|
mv /tmp/disko-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
|
||||||
@@ -168,7 +167,7 @@ module and `disko-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:
|
||||||
|
|
||||||
```
|
```nix
|
||||||
imports =
|
imports =
|
||||||
[ # Include the results of the hardware scan.
|
[ # Include the results of the hardware scan.
|
||||||
./hardware-configuration.nix
|
./hardware-configuration.nix
|
||||||
@@ -186,7 +185,7 @@ 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 will
|
**Note:** Its not necessary to set `boot.loader.grub.device` here, since Disko will
|
||||||
take care of that automatically.
|
take care of that automatically.
|
||||||
|
|
||||||
```
|
```nix
|
||||||
# ...
|
# ...
|
||||||
#boot.loader.systemd-boot.enable = true;
|
#boot.loader.systemd-boot.enable = true;
|
||||||
#boot.loader.efi.canTouchEfiVariables = true;
|
#boot.loader.efi.canTouchEfiVariables = true;
|
||||||
@@ -198,7 +197,7 @@ take care of that automatically.
|
|||||||
|
|
||||||
f) Finish the installation and reboot your machine,
|
f) Finish the installation and reboot your machine,
|
||||||
|
|
||||||
```
|
```console
|
||||||
$ nixos-install
|
nixos-install
|
||||||
$ reboot
|
reboot
|
||||||
```
|
```
|
||||||
+3
-3
@@ -53,13 +53,13 @@ generate disk images:
|
|||||||
|
|
||||||
1. **Build the disko image script:** Replace `mySystem` in the command below with your
|
1. **Build the disko image script:** Replace `mySystem` in the command below with your
|
||||||
specific system configuration name:
|
specific system configuration name:
|
||||||
```bash
|
```console
|
||||||
nix build .#nixosConfigurations.mySystem.config.system.build.diskoImagesScript
|
nix build .#nixosConfigurations.mySystem.config.system.build.diskoImagesScript
|
||||||
```
|
```
|
||||||
2. **Execute the result file:** Execute the generated result file. Running
|
2. **Execute the result file:** Execute the generated result file. Running
|
||||||
`./result --help` will output the available options:
|
`./result --help` will output the available options:
|
||||||
|
|
||||||
```
|
```console
|
||||||
./result --help
|
./result --help
|
||||||
Usage: $script [options]
|
Usage: $script [options]
|
||||||
|
|
||||||
@@ -85,7 +85,7 @@ generate disk images:
|
|||||||
|
|
||||||
- For virtual drive use, define the image size in your Disko configuration:
|
- For virtual drive use, define the image size in your Disko configuration:
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
disko.devices.disk.<drive>.imageSize = "32G"; # Set your preferred size
|
disko.devices.disk.<drive>.imageSize = "32G"; # Set your preferred size
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,22 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
a = {
|
||||||
|
type = "disk";
|
||||||
|
device = "/dev/sda";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
zfs = {
|
||||||
|
size = "100%";
|
||||||
|
content = {
|
||||||
|
type = "zfs";
|
||||||
|
pool = "storage2";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
zpool = {
|
zpool = {
|
||||||
storage = {
|
storage = {
|
||||||
@@ -73,6 +89,20 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
storage2 = {
|
||||||
|
type = "zpool";
|
||||||
|
mountpoint = "/storage2";
|
||||||
|
rootFsOptions = {
|
||||||
|
canmount = "off";
|
||||||
|
};
|
||||||
|
|
||||||
|
datasets = {
|
||||||
|
dataset = {
|
||||||
|
type = "zfs_fs";
|
||||||
|
mountpoint = "/storage2/dataset";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+3
-3
@@ -2,11 +2,11 @@
|
|||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1702539185,
|
"lastModified": 1704008649,
|
||||||
"narHash": "sha256-KnIRG5NMdLIpEkZTnN5zovNYc0hhXjAgv6pfd5Z4c7U=",
|
"narHash": "sha256-rGPSWjXTXTurQN9beuHdyJhB8O761w1Zc5BqSSmHvoM=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "aa9d4729cbc99dabacb50e3994dcefb3ea0f7447",
|
"rev": "d44d59d2b5bd694cd9d996fd8c51d03e3e9ba7f7",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
+13
-3
@@ -18,9 +18,19 @@ in
|
|||||||
type = lib.types.attrsOf (lib.types.submodule ({ name, ... }@partition: {
|
type = lib.types.attrsOf (lib.types.submodule ({ name, ... }@partition: {
|
||||||
options = {
|
options = {
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
type = lib.types.strMatching "[A-Fa-f0-9]{4}";
|
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 = "8300";
|
default = "8300";
|
||||||
description = "Filesystem type to use, run sgdisk -L to see what is available";
|
description = ''
|
||||||
|
Filesystem type to use.
|
||||||
|
This can either be an sgdisk-specific short code (run sgdisk -L to see what is available),
|
||||||
|
or a fully specified GUID (see https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs).
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
device = lib.mkOption {
|
device = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
@@ -76,7 +86,7 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
default = {};
|
default = { };
|
||||||
description = "Attrs of partitions to add to the partition table";
|
description = "Attrs of partitions to add to the partition table";
|
||||||
};
|
};
|
||||||
_parent = lib.mkOption {
|
_parent = lib.mkOption {
|
||||||
|
|||||||
+15
-10
@@ -15,10 +15,17 @@ let
|
|||||||
+ "Use passwordFile instead if you want to use interactive login or settings.keyFile if you want to use key file login")
|
+ "Use passwordFile instead if you want to use interactive login or settings.keyFile if you want to use key file login")
|
||||||
config.keyFile
|
config.keyFile
|
||||||
else null;
|
else null;
|
||||||
keyFileArgs = ''\
|
keyFileArgs = ''
|
||||||
${lib.optionalString (keyFile != null) "--key-file ${keyFile}"} \
|
${lib.optionalString (keyFile != null) "--key-file ${keyFile}"} \
|
||||||
${lib.optionalString (lib.hasAttr "keyFileSize" config.settings) "--keyfile-size ${builtins.toString config.settings.keyFileSize}"} \
|
${lib.optionalString (lib.hasAttr "keyFileSize" config.settings) "--keyfile-size ${builtins.toString config.settings.keyFileSize}"} \
|
||||||
${lib.optionalString (lib.hasAttr "keyFileOffset" config.settings) "--keyfile-offset ${builtins.toString config.settings.keyFileOffset}"}
|
${lib.optionalString (lib.hasAttr "keyFileOffset" config.settings) "--keyfile-offset ${builtins.toString config.settings.keyFileOffset}"} \
|
||||||
|
'';
|
||||||
|
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"} \
|
||||||
|
${toString config.extraOpenArgs} \
|
||||||
|
${keyFileArgs} \
|
||||||
'';
|
'';
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
@@ -120,12 +127,11 @@ in
|
|||||||
done
|
done
|
||||||
set -x
|
set -x
|
||||||
''}
|
''}
|
||||||
cryptsetup -q luksFormat ${config.device} ${toString config.extraFormatArgs} \
|
cryptsetup -q luksFormat ${config.device} ${toString config.extraFormatArgs} ${keyFileArgs}
|
||||||
${keyFileArgs}
|
${cryptsetupOpen} --persistent
|
||||||
cryptsetup open ${config.device} ${config.name} \
|
${toString (lib.forEach config.additionalKeyFiles (keyFile: ''
|
||||||
${toString config.extraOpenArgs} \
|
cryptsetup luksAddKey ${config.device} ${keyFile} ${keyFileArgs}
|
||||||
${keyFileArgs}
|
''))}
|
||||||
${toString (lib.lists.forEach config.additionalKeyFiles (x: "cryptsetup luksAddKey ${config.device} ${x} ${keyFileArgs}"))}
|
|
||||||
${lib.optionalString (config.content != null) config.content._create}
|
${lib.optionalString (config.content != null) config.content._create}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
@@ -145,8 +151,7 @@ in
|
|||||||
export password
|
export password
|
||||||
set -x
|
set -x
|
||||||
''}
|
''}
|
||||||
cryptsetup open ${config.device} ${config.name} \
|
${cryptsetupOpen}
|
||||||
${keyFileArgs}
|
|
||||||
fi
|
fi
|
||||||
${lib.optionalString (config.content != null) contentMount.dev or ""}
|
${lib.optionalString (config.content != null) contentMount.dev or ""}
|
||||||
'';
|
'';
|
||||||
|
|||||||
+22
-7
@@ -6,17 +6,27 @@
|
|||||||
default = config._module.args.name;
|
default = config._module.args.name;
|
||||||
description = "Name of the dataset";
|
description = "Name of the dataset";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_name = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "${config._parent.name}/${config.name}";
|
||||||
|
internal = true;
|
||||||
|
description = "Fully quantified name for dataset";
|
||||||
|
};
|
||||||
|
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
type = lib.types.enum [ "zfs_fs" ];
|
type = lib.types.enum [ "zfs_fs" ];
|
||||||
default = "zfs_fs";
|
default = "zfs_fs";
|
||||||
internal = true;
|
internal = true;
|
||||||
description = "Type";
|
description = "Type";
|
||||||
};
|
};
|
||||||
|
|
||||||
options = lib.mkOption {
|
options = lib.mkOption {
|
||||||
type = lib.types.attrsOf lib.types.str;
|
type = lib.types.attrsOf lib.types.str;
|
||||||
default = { };
|
default = { };
|
||||||
description = "Options to set for the dataset";
|
description = "Options to set for the dataset";
|
||||||
};
|
};
|
||||||
|
|
||||||
mountOptions = lib.mkOption {
|
mountOptions = lib.mkOption {
|
||||||
type = lib.types.listOf lib.types.str;
|
type = lib.types.listOf lib.types.str;
|
||||||
default = [ "defaults" ];
|
default = [ "defaults" ];
|
||||||
@@ -33,6 +43,7 @@
|
|||||||
internal = true;
|
internal = true;
|
||||||
default = parent;
|
default = parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
_meta = lib.mkOption {
|
_meta = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
@@ -40,6 +51,7 @@
|
|||||||
default = _dev: { };
|
default = _dev: { };
|
||||||
description = "Metadata";
|
description = "Metadata";
|
||||||
};
|
};
|
||||||
|
|
||||||
_create = diskoLib.mkCreateOption {
|
_create = diskoLib.mkCreateOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
# -u prevents mounting newly created datasets, which is
|
# -u prevents mounting newly created datasets, which is
|
||||||
@@ -47,17 +59,18 @@
|
|||||||
# since (create order != mount order)
|
# since (create order != mount order)
|
||||||
# -p creates parents automatically
|
# -p creates parents automatically
|
||||||
default = ''
|
default = ''
|
||||||
zfs create -up ${config._parent.name}/${config.name} \
|
zfs create -up ${config._name} \
|
||||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)}
|
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)}
|
||||||
'';
|
'';
|
||||||
};
|
} // { readOnly = false; };
|
||||||
|
|
||||||
_mount = diskoLib.mkMountOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default =
|
default =
|
||||||
lib.optionalAttrs (config.options.mountpoint or "" != "none") {
|
lib.optionalAttrs (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") {
|
||||||
fs.${config.mountpoint} = ''
|
fs.${config.mountpoint} = ''
|
||||||
if ! findmnt ${config._parent.name}/${config.name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
|
if ! findmnt ${config._name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
|
||||||
mount ${config._parent.name}/${config.name} "${rootMountPoint}${config.mountpoint}" \
|
mount ${config._name} "${rootMountPoint}${config.mountpoint}" \
|
||||||
-o X-mount.mkdir \
|
-o X-mount.mkdir \
|
||||||
${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
|
${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
|
||||||
${lib.optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \
|
${lib.optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \
|
||||||
@@ -66,19 +79,21 @@
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
_config = lib.mkOption {
|
_config = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default =
|
default =
|
||||||
lib.optional (config.options.mountpoint or "" != "none") {
|
lib.optional (config.options.mountpoint or "" != "none" && config.options.canmount or "" != "off") {
|
||||||
fileSystems.${config.mountpoint} = {
|
fileSystems.${config.mountpoint} = {
|
||||||
device = "${config._parent.name}/${config.name}";
|
device = "${config._name}";
|
||||||
fsType = "zfs";
|
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";
|
description = "NixOS configuration";
|
||||||
};
|
};
|
||||||
|
|
||||||
_pkgs = lib.mkOption {
|
_pkgs = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
|
|||||||
+14
-23
@@ -67,9 +67,9 @@
|
|||||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
|
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") config.options)} \
|
||||||
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \
|
${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-O ${n}=${v}") config.rootFsOptions)} \
|
||||||
"''${zfs_devices[@]}"
|
"''${zfs_devices[@]}"
|
||||||
${lib.optionalString ((config.rootFsOptions.mountpoint or "") != "none") ''
|
if [[ $(zfs get -H mounted ${config.name} | cut -f3) == "yes" ]]; then
|
||||||
zfs unmount ${config.name}
|
zfs unmount ${config.name}
|
||||||
''}
|
fi
|
||||||
${lib.concatMapStrings (dataset: dataset._create) (lib.attrValues config.datasets)}
|
${lib.concatMapStrings (dataset: dataset._create) (lib.attrValues config.datasets)}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
@@ -85,32 +85,13 @@
|
|||||||
zpool import -l -R ${rootMountPoint} '${config.name}'
|
zpool import -l -R ${rootMountPoint} '${config.name}'
|
||||||
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues datasetMounts)}
|
${lib.concatMapStrings (x: x.dev or "") (lib.attrValues datasetMounts)}
|
||||||
'';
|
'';
|
||||||
fs = (datasetMounts.fs or { }) // lib.optionalAttrs (config.mountpoint != null) {
|
inherit (datasetMounts) fs;
|
||||||
${config.mountpoint} = ''
|
|
||||||
if ! findmnt ${config.name} "${rootMountPoint}${config.mountpoint}" >/dev/null 2>&1; then
|
|
||||||
mount ${config.name} "${rootMountPoint}${config.mountpoint}" \
|
|
||||||
${lib.optionalString ((config.options.mountpoint or "") != "legacy") "-o zfsutil"} \
|
|
||||||
${lib.concatMapStringsSep " " (opt: "-o ${opt}") config.mountOptions} \
|
|
||||||
-o X-mount.mkdir \
|
|
||||||
-t zfs
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
_config = lib.mkOption {
|
_config = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default = [
|
default = map (dataset: dataset._config) (lib.attrValues config.datasets);
|
||||||
(map (dataset: dataset._config) (lib.attrValues config.datasets))
|
|
||||||
(lib.optional (config.mountpoint != null) {
|
|
||||||
fileSystems.${config.mountpoint} = {
|
|
||||||
device = config.name;
|
|
||||||
fsType = "zfs";
|
|
||||||
options = config.mountOptions ++ lib.optional ((config.options.mountpoint or "") != "legacy") "zfsutil";
|
|
||||||
};
|
|
||||||
})
|
|
||||||
];
|
|
||||||
description = "NixOS configuration";
|
description = "NixOS configuration";
|
||||||
};
|
};
|
||||||
_pkgs = lib.mkOption {
|
_pkgs = lib.mkOption {
|
||||||
@@ -121,4 +102,14 @@
|
|||||||
description = "Packages";
|
description = "Packages";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
datasets."__root" = {
|
||||||
|
_name = config.name;
|
||||||
|
_create = "";
|
||||||
|
type = "zfs_fs";
|
||||||
|
mountpoint = config.mountpoint;
|
||||||
|
options = config.rootFsOptions;
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
+5
-5
@@ -11,11 +11,11 @@ in
|
|||||||
{
|
{
|
||||||
options.disko = {
|
options.disko = {
|
||||||
extraRootModules = lib.mkOption {
|
extraRootModules = lib.mkOption {
|
||||||
type = lib.types.listOf lib.types.str ;
|
type = lib.types.listOf lib.types.str;
|
||||||
description = ''
|
description = ''
|
||||||
extra modules to pass to the vmTools.runCommand invocation in the make-disk-image.nix builder
|
extra modules to pass to the vmTools.runCommand invocation in the make-disk-image.nix builder
|
||||||
'';
|
'';
|
||||||
default = [];
|
default = [ ];
|
||||||
};
|
};
|
||||||
memSize = lib.mkOption {
|
memSize = lib.mkOption {
|
||||||
type = lib.types.int;
|
type = lib.types.int;
|
||||||
@@ -34,7 +34,7 @@ in
|
|||||||
description = ''
|
description = ''
|
||||||
list of extra packages to make available in the make-disk-image.nix VM builder, an example might be f2fs-tools
|
list of extra packages to make available in the make-disk-image.nix VM builder, an example might be f2fs-tools
|
||||||
'';
|
'';
|
||||||
default = [];
|
default = [ ];
|
||||||
};
|
};
|
||||||
rootMountPoint = lib.mkOption {
|
rootMountPoint = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
@@ -90,8 +90,8 @@ in
|
|||||||
system.build = (cfg.devices._scripts { inherit pkgs; checked = cfg.checkScripts; }) // {
|
system.build = (cfg.devices._scripts { inherit pkgs; checked = cfg.checkScripts; }) // {
|
||||||
|
|
||||||
# we keep these old outputs for compatibility
|
# we keep these old outputs for compatibility
|
||||||
disko = builtins.trace "the .disko output is deprecated, please use .diskoScript instead" (cfg.devices._scripts pkgs).diskoScript;
|
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 pkgs).diskoScriptNoDeps;
|
diskoNoDeps = builtins.trace "the .diskoNoDeps output is deprecated, please use .diskoScriptNoDeps instead" (cfg.devices._scripts { inherit pkgs; }).diskoScriptNoDeps;
|
||||||
|
|
||||||
diskoImages = diskoLib.makeDiskImages {
|
diskoImages = diskoLib.makeDiskImages {
|
||||||
nixosConfig = args;
|
nixosConfig = args;
|
||||||
|
|||||||
+23
-1
@@ -14,13 +14,35 @@ diskoLib.testLib.makeDiskoTest {
|
|||||||
filesystem = machine.execute("stat --file-system --format=%T /mnt/storage")[1].rstrip()
|
filesystem = machine.execute("stat --file-system --format=%T /mnt/storage")[1].rstrip()
|
||||||
print(f"/mnt/storage {filesystem=}")
|
print(f"/mnt/storage {filesystem=}")
|
||||||
assert filesystem == "zfs", "/mnt/storage is not ZFS"
|
assert filesystem == "zfs", "/mnt/storage is not ZFS"
|
||||||
|
|
||||||
|
machine.fail("mountpoint /mnt/storage2")
|
||||||
|
machine.succeed("mountpoint /mnt/storage2/dataset")
|
||||||
|
|
||||||
|
filesystem = machine.execute("stat --file-system --format=%T /mnt/storage2")[1].rstrip()
|
||||||
|
print(f"/mnt/storage2 {filesystem=}")
|
||||||
|
assert filesystem != "zfs", "/mnt/storage should not be ZFS"
|
||||||
|
|
||||||
|
filesystem = machine.execute("stat --file-system --format=%T /mnt/storage2/dataset")[1].rstrip()
|
||||||
|
print(f"/mnt/storage2/dataset {filesystem=}")
|
||||||
|
assert filesystem == "zfs", "/mnt/storage/dataset is not ZFS"
|
||||||
'';
|
'';
|
||||||
extraTestScript = ''
|
extraTestScript = ''
|
||||||
machine.succeed("mountpoint /storage")
|
machine.succeed("mountpoint /storage")
|
||||||
machine.succeed("mountpoint /storage/dataset")
|
machine.succeed("mountpoint /storage/dataset")
|
||||||
|
|
||||||
filesystem = machine.execute("stat --file-system --format=%T /storage")[1].rstrip()
|
filesystem = machine.execute("stat --file-system --format=%T /storage")[1].rstrip()
|
||||||
print(f"/mnt/storage {filesystem=}")
|
print(f"/storage {filesystem=}")
|
||||||
assert filesystem == "zfs", "/storage is not ZFS"
|
assert filesystem == "zfs", "/storage is not ZFS"
|
||||||
|
|
||||||
|
machine.fail("mountpoint /storage2")
|
||||||
|
machine.succeed("mountpoint /storage2/dataset")
|
||||||
|
|
||||||
|
filesystem = machine.execute("stat --file-system --format=%T /storage2")[1].rstrip()
|
||||||
|
print(f"/storage2 {filesystem=}")
|
||||||
|
assert filesystem != "zfs", "/storage should not be ZFS"
|
||||||
|
|
||||||
|
filesystem = machine.execute("stat --file-system --format=%T /storage2/dataset")[1].rstrip()
|
||||||
|
print(f"/storage2/dataset {filesystem=}")
|
||||||
|
assert filesystem == "zfs", "/storage/dataset is not ZFS"
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user