ZFS: Difference between revisions
m Add command for finding what kernel modules are needed. |
→Take snapshots automatically: add services.zfs.autoSnapshot |
||
(12 intermediate revisions by 4 users not shown) | |||
Line 65: | Line 65: | ||
== Guides == | == Guides == | ||
=== | === Root on ZFS with disko === | ||
disko[https://github.com/nix-community/disko/blob/master/example/zfs.nix] can partition disks declaratively and handle mount points at install time. | |||
Don't follow the Root on ZFS guide found in OpenZFS documentation. It was abandoned and has not been updated in years. See commit log for the openzfs-docs repo for details. | |||
=== Simple NixOS ZFS on root installation === | === Simple NixOS ZFS on root installation === | ||
Line 426: | Line 419: | ||
== Take snapshots automatically == | == Take snapshots automatically == | ||
See {{nixos:option|services.sanoid}} section in <code>man configuration.nix</code>. | See {{nixos:option|services.zfs.autoSnapshot}} or {{nixos:option|services.sanoid}} section in <code>man configuration.nix</code>. | ||
== NFS share == | == NFS share == | ||
Line 441: | Line 434: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Only this line is needed. Configure firewall if necessary, as described in [[NFS]] article. | Only this line is needed. Configure firewall if necessary, as described in [[NFS]] article. | ||
{{warning|<code>zfs share</code> or <code>sharenfs</code> does not work if the <code>mountpoint</code> is set to <code>legacy</code> (or <code>none</code>, of course). I was unable to find a source for this behaviour, but I was stuck on the problem for days, until I realized the problem. ::Reply: sharenfs controlls what | |||
is written into <code>/etc/exports</code>. If ZFS does not know the mountpoint, as is the case in | |||
mountpoint legacy or none, the contents of <code>/etc/exports</code> would be wrong}} | |||
Then, set <code>sharenfs</code> property: | Then, set <code>sharenfs</code> property: | ||
Line 453: | Line 450: | ||
ZFS Event Daemon (zed) monitors events generated by the ZFS Kernel module and runs configured tasks. It can be configured to send an email when a pool scrub is finished or a disk has failed. [https://search.nixos.org/options?query=services.zfs.zed zed options] | ZFS Event Daemon (zed) monitors events generated by the ZFS Kernel module and runs configured tasks. It can be configured to send an email when a pool scrub is finished or a disk has failed. [https://search.nixos.org/options?query=services.zfs.zed zed options] | ||
First, we need to configure a mail transfer agent, the program that sends email: | First, we need to configure a mail transfer agent, the program that sends email: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ | { | ||
age.secrets.msmtp = { | |||
file = "${inputs.self.outPath}/secrets/msmtp.age"; | |||
}; | |||
# for zed enableMail, enable sendmailSetuidWrapper | |||
services.mail.sendmailSetuidWrapper.enable = true; | |||
programs.msmtp = { | programs.msmtp = { | ||
enable = true; | enable = true; | ||
Line 464: | Line 466: | ||
defaults = { | defaults = { | ||
aliases = "/etc/aliases"; | aliases = "/etc/aliases"; | ||
port = | port = 587; | ||
auth = "plain"; | |||
tls = "on"; | tls = "on"; | ||
tls_starttls = "on"; | |||
tls_starttls = " | |||
}; | }; | ||
accounts = { | accounts = { | ||
default = { | default = { | ||
host = "mail.example.com"; | host = "smtp.mail.example.com"; | ||
passwordeval = "cat | passwordeval = "cat ${config.age.secrets.msmtp.path}"; | ||
user = " | user = "myname@example.com"; | ||
from = " | from = "myname@example.com"; | ||
}; | }; | ||
}; | }; | ||
Line 487: | Line 488: | ||
{ | { | ||
environment.etc.aliases.text = '' | environment.etc.aliases.text = '' | ||
root: | root: admin@example.com | ||
''; | ''; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Finally, | Finally, enable zed mail notification: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
{ | { | ||
services.zfs.zed. | services.zfs.zed. = { | ||
enableMail = true; | |||
ZED_EMAIL_ADDR = [ "root" ]; | settings = { | ||
ZED_EMAIL_ADDR = [ "root" ]; | |||
# send notification if scrub succeeds | |||
ZED_NOTIFY_VERBOSE = true; | |||
}; | |||
}; | }; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 517: | Line 512: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Guide]] | [[Category:Guide]] |