New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tasks/btrfs: add services.btrfs.autoScrub #32496
Conversation
} | ||
]; | ||
|
||
# This will yield duplicated units when If the user mounts a filesystem multiple times |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems a bit strange here: "… units when If the user …"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the hint!
@@ -31,5 +68,56 @@ in | |||
'' | |||
btrfs device scan | |||
''; | |||
}; | |||
} | |||
// mkIf cfgScrub.enable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work as expected, I though you needed to have mkMerge
or something? In particular, I would assume the //
will remove the (any (fs: fs == "btrfs") config.boot.supportedFilesystems)
condition of the above code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indeed broke my initrd, as I discovered on booting today, argh. 🤦 You're totally right.
I updated it to use mkMerge
in a similar way to what the zfs module does, now I see why they're doing it that way.
27fdcc8
to
a080e74
Compare
I additionally added a paragraph about this option to the 1803 changelog. |
services.btrfs.autoScrub.fileSystems = mkDefault (mapAttrsToList (name: fs: fs.mountPoint) | ||
(filterAttrs (name: fs: fs.fsType == "btrfs") config.fileSystems)); | ||
|
||
# did not manage to do it via the usual btrfs-scrub@.timer/.service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious, what issues did you encounter using the template units?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Not a blocker, just to be clear)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joachifm the full story:
What I initially tried to achieve was this, which seems to be the usual solution on other distros (copied from Arch Linux):
btrfs-scrub@.timer
:
[Unit]
Description=Monthly Btrfs scrub on %f
[Timer]
OnCalendar=monthly
AccuracySec=1d
Persistent=true
[Install]
WantedBy=multi-user.target
btrfs-scrub@.service
:
[Unit]
Description=Btrfs scrub on %f
[Service]
Nice=19
IOSchedulingClass=idle
ExecStart=/usr/bin/btrfs scrub start -B %f
enabling specific units for scrubbing:
> systemctl enable btrfs-scrub@$(systemd-escape /).timer
Created symlink /etc/systemd/system/multi-user.target.wants/btrfs-scrub@-.timer → /usr/lib/systemd/system/btrfs-scrub@.timer.
> systemctl enable btrfs-scrub@$(systemd-escape /home).timer
Created symlink /etc/systemd/system/multi-user.target.wants/btrfs-scrub@-home.timer → /usr/lib/systemd/system/btrfs-scrub@.timer.
each parameterized timer unit will execute a corresponding parameterized service unit.
My issues:
Packing the units (without [Install], of course) works fine using systemd.services/timers."btrfs-scrub@"
. But enabling the parameterized timers was problematic: I came up with a few variants (should have kept the code to show it to you…), trying to use wants
/ wantedBy
and aliases
to create the required symlinks. But as soon as something like that is added to the timer, the timer file suddenly is empty like this:
[Unit]
[Timer]
without any error message. The only thing I noted in the logs was that sometimes it tried to start btrfs-scrub@timers.timer
, but I have no idea where the timers
parameterization came from - from timers.target
? But how?
(I found no exapmle in NixOS where something similar is done.)
So I tried to have only a single timer, activating a list of services, but a timer can only start a single services. Which lead me to the non-templated version you see here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, alright, well I guess this can be rectified later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I was not sure whether that is actually wanted or preffered vs letting nix do all the work.
I extended the comment a little describing the issue, and marked it as a TODO.
a9f55e6
to
be2d9bc
Compare
for automatic regular scrubbing of mounted btrfs filesystems, similar to what's already there for zfs.
be2d9bc
to
fc21593
Compare
for automatic regular scrubbing of mounted btrfs filesystems,
similar to what's already there for zfs.
Motivation for this change
Regular scrubs make sure bitrot gets detected early, and gets corrected when there's a copy available. 🔧
Things done
build-use-sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)