mirror of
https://codeberg.org/privacy1st/nix-git
synced 2024-11-21 22:03:19 +01:00
refactor: btrfs-scrub module
This commit is contained in:
parent
9c722985e4
commit
3439bd5ac5
@ -59,10 +59,13 @@ in
|
|||||||
#../../modules/veracrypt.nix
|
#../../modules/veracrypt.nix
|
||||||
../../modules/btrbk
|
../../modules/btrbk
|
||||||
../../modules/spin-down.nix
|
../../modules/spin-down.nix
|
||||||
|
|
||||||
|
../../modules/btrfs-scrub.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
networking.hostName = "yodaNas";
|
networking.hostName = "yodaNas";
|
||||||
boot.initrd.luks.devices."luks-3d974bd0-f373-469b-8e9c-2d5516e9f0f5".allowDiscards = true;
|
boot.initrd.luks.devices."luks-3d974bd0-f373-469b-8e9c-2d5516e9f0f5".allowDiscards = true;
|
||||||
|
yoda.btrfs-scrub = ["/" "/mnt/data" "/mnt/backup"];
|
||||||
|
|
||||||
boot.kernelParams = [];
|
boot.kernelParams = [];
|
||||||
|
|
||||||
|
@ -58,11 +58,14 @@ in
|
|||||||
#../../modules/veracrypt.nix
|
#../../modules/veracrypt.nix
|
||||||
#../../modules/btrbk
|
#../../modules/btrbk
|
||||||
#../../modules/spin-down.nix
|
#../../modules/spin-down.nix
|
||||||
|
|
||||||
|
../../modules/btrfs-scrub.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
networking.hostName = "yodaTab";
|
networking.hostName = "yodaTab";
|
||||||
boot.initrd.luks.devices."luks-ba8b94d0-7f70-496a-ad87-eadc5e852aad".allowDiscards = true;
|
boot.initrd.luks.devices."luks-ba8b94d0-7f70-496a-ad87-eadc5e852aad".allowDiscards = true;
|
||||||
boot.initrd.luks.devices."512gb".allowDiscards = true;
|
boot.initrd.luks.devices."512gb".allowDiscards = true;
|
||||||
|
yoda.btrfs-scrub = ["/"];
|
||||||
|
|
||||||
boot.kernelParams = [];
|
boot.kernelParams = [];
|
||||||
|
|
||||||
|
@ -58,10 +58,13 @@ in
|
|||||||
#../../modules/veracrypt.nix
|
#../../modules/veracrypt.nix
|
||||||
#../../modules/btrbk
|
#../../modules/btrbk
|
||||||
#../../modules/spin-down.nix
|
#../../modules/spin-down.nix
|
||||||
|
|
||||||
|
../../modules/btrfs-scrub.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
networking.hostName = "yodaTux";
|
networking.hostName = "yodaTux";
|
||||||
boot.initrd.luks.devices."luks-ea7099e3-320d-4eb3-a4c3-9910a9af817b".allowDiscards = true;
|
boot.initrd.luks.devices."luks-ea7099e3-320d-4eb3-a4c3-9910a9af817b".allowDiscards = true;
|
||||||
|
yoda.btrfs-scrub = ["/"];
|
||||||
|
|
||||||
# Systemd Journal entry:
|
# Systemd Journal entry:
|
||||||
# S Sat Sep 23 16:11:52 2023 p4 kernel: TSC found unstable after boot, most likely due to broken BIOS. Use 'tsc=unstable'.
|
# S Sat Sep 23 16:11:52 2023 p4 kernel: TSC found unstable after boot, most likely due to broken BIOS. Use 'tsc=unstable'.
|
||||||
|
@ -59,10 +59,13 @@ in
|
|||||||
#../../modules/veracrypt.nix
|
#../../modules/veracrypt.nix
|
||||||
#../../modules/btrbk
|
#../../modules/btrbk
|
||||||
#../../modules/spin-down.nix
|
#../../modules/spin-down.nix
|
||||||
|
|
||||||
|
../../modules/btrfs-scrub.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
networking.hostName = "yodaYoga";
|
networking.hostName = "yodaYoga";
|
||||||
boot.initrd.luks.devices."luks-a8521407-e25b-4f26-8e7a-a56fcbfd2e35".allowDiscards = true;
|
boot.initrd.luks.devices."luks-a8521407-e25b-4f26-8e7a-a56fcbfd2e35".allowDiscards = true;
|
||||||
|
yoda.btrfs-scrub = ["/"];
|
||||||
|
|
||||||
boot.kernelParams = [];
|
boot.kernelParams = [];
|
||||||
|
|
||||||
|
@ -98,27 +98,6 @@
|
|||||||
"/".options = [ "compress=zstd" "noatime" "commit=120" ];
|
"/".options = [ "compress=zstd" "noatime" "commit=120" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
# BTRFS scrub.
|
|
||||||
#
|
|
||||||
# Scrubbing is the process of checking file consistency.
|
|
||||||
# Scrubbing may be done "online", meaning you don't need to unmount a subvolume to scrub it.
|
|
||||||
# https://nixos.wiki/wiki/Btrfs#Scrubbing
|
|
||||||
# Btrfs scrub is "[a]n online filesystem checking tool. Reads all the data and metadata on the filesystem and uses checksums and the duplicate copies from RAID storage to identify and repair any corrupt data."
|
|
||||||
# https://wiki.archlinux.org/title/btrfs#Scrub
|
|
||||||
# The scrub command operates on a whole filesystem, not just individual subvolumes.
|
|
||||||
# https://unix.stackexchange.com/a/724412
|
|
||||||
#
|
|
||||||
# As this command reads all data, it wears down the disk. One should not run it too often. For large, slow disks once per month should be fine.
|
|
||||||
#
|
|
||||||
# To run it manually:
|
|
||||||
# sudo btrfs scrub start /
|
|
||||||
# sudo btrfs scrub status /
|
|
||||||
services.btrfs.autoScrub = {
|
|
||||||
enable = true;
|
|
||||||
interval = "monthly";
|
|
||||||
fileSystems = [ "/" ];
|
|
||||||
};
|
|
||||||
|
|
||||||
nix.settings.auto-optimise-store = true;
|
nix.settings.auto-optimise-store = true;
|
||||||
|
|
||||||
# https://nixos.wiki/wiki/Storage_optimization#Automation
|
# https://nixos.wiki/wiki/Storage_optimization#Automation
|
||||||
|
41
modules/btrfs-scrub.nix
Normal file
41
modules/btrfs-scrub.nix
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# BTRFS scrub.
|
||||||
|
#
|
||||||
|
# Scrubbing is the process of checking file consistency.
|
||||||
|
# Scrubbing may be done "online", meaning you don't need to unmount a subvolume to scrub it.
|
||||||
|
# https://nixos.wiki/wiki/Btrfs#Scrubbing
|
||||||
|
# Btrfs scrub is "[a]n online filesystem checking tool. Reads all the data and metadata on the filesystem and uses checksums and the duplicate copies from RAID storage to identify and repair any corrupt data."
|
||||||
|
# https://wiki.archlinux.org/title/btrfs#Scrub
|
||||||
|
# The scrub command operates on a whole filesystem, not just individual subvolumes.
|
||||||
|
# https://unix.stackexchange.com/a/724412
|
||||||
|
#
|
||||||
|
# As this command reads all data, it wears down the disk. One should not run it too often. For large, slow disks once per month should be fine.
|
||||||
|
#
|
||||||
|
# To run it manually:
|
||||||
|
# sudo btrfs scrub start /
|
||||||
|
# sudo btrfs scrub status /
|
||||||
|
|
||||||
|
{ lib, config, options, pkgs, modulesPath, ... }:
|
||||||
|
with lib;
|
||||||
|
let
|
||||||
|
cfg = config.yoda.btrfs-scrub;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
yoda.btrfs-scrub = mkOption {
|
||||||
|
type = types.listOf types.path;
|
||||||
|
default = ["/"];
|
||||||
|
example = ["/" "/mnt/data"];
|
||||||
|
description = ''
|
||||||
|
List containing each mounted BTRFS filesystem once.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf (length cfg > 0) {
|
||||||
|
services.btrfs.autoScrub = {
|
||||||
|
enable = true;
|
||||||
|
interval = "monthly";
|
||||||
|
fileSystems = cfg;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user