1.4 KiB
1.4 KiB
zfs-containers
Use ZFS datasets in NixOS containers
zfs zone allows you to attach ZFS datasets to user namespaces. Specific datasets on the host can be used within a systemd-nspawn container, including mounting, creating sub-datasets, and changing properties (with some limitations).
Usage
Add to flake inputs
inputs.zfs-containers.url = "git+https://gitea.mregirouard.com/nix/zfs-containers.git";
Add module
nixosConfigurations.my-system = nixpkgs.lib.nixosSystem {
modules = [
inputs.zfs-containers.nixosModules.default
# ...
];
# ...
};
Create containers
containers.my-container = {
zfs_datasets = [
"tank/data"
];
# ...
};
Use ZFS datasets
$ sudo machinectl shell my-container
[root@my-container:~]# zfs list
NAME USED AVAIL REFER MOUNTPOINT
tank 180G 820G 96K none
tank/data 96K 820G 96K none
[root@my-container:~]# zfs create tank/data/files
# ...
Systemd Target
ZFS datasets will not immediately become available on container startup. A systemd target zfs will be created in the container that will become active when all datasets have been attached to the container. For services that depend on dataset availability, set Requires = zfs.target in your unit file.