refactor: btrfs-mount-options module

This commit is contained in:
Daniel Langbein 2023-10-09 10:46:57 +02:00
parent 3439bd5ac5
commit 045858b536
Signed by: langfingaz
GPG Key ID: 6C47C753F0823002
7 changed files with 57 additions and 24 deletions

View File

@ -61,11 +61,13 @@ in
../../modules/spin-down.nix
../../modules/btrfs-scrub.nix
../../modules/btrfs-mount-options.nix
];
networking.hostName = "yodaNas";
boot.initrd.luks.devices."luks-3d974bd0-f373-469b-8e9c-2d5516e9f0f5".allowDiscards = true;
yoda.btrfs-scrub = ["/" "/mnt/data" "/mnt/backup"];
yoda.btrfsFileSystems = ["/" "/mnt/data" "/mnt/backup"];
#yoda.btrfsMounts = yoda.btrfsFileSystems;
boot.kernelParams = [];

View File

@ -60,12 +60,14 @@ in
#../../modules/spin-down.nix
../../modules/btrfs-scrub.nix
../../modules/btrfs-mount-options.nix
];
networking.hostName = "yodaTab";
boot.initrd.luks.devices."luks-ba8b94d0-7f70-496a-ad87-eadc5e852aad".allowDiscards = true;
boot.initrd.luks.devices."512gb".allowDiscards = true;
yoda.btrfs-scrub = ["/"];
yoda.btrfsFileSystems = ["/"];
#yoda.btrfsMounts = yoda.btrfsFileSystems;
boot.kernelParams = [];

View File

@ -60,11 +60,13 @@ in
#../../modules/spin-down.nix
../../modules/btrfs-scrub.nix
../../modules/btrfs-mount-options.nix
];
networking.hostName = "yodaTux";
boot.initrd.luks.devices."luks-ea7099e3-320d-4eb3-a4c3-9910a9af817b".allowDiscards = true;
yoda.btrfs-scrub = ["/"];
yoda.btrfsFileSystems = ["/"];
#yoda.btrfsMounts = yoda.btrfsFileSystems;
# 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'.

View File

@ -61,11 +61,13 @@ in
#../../modules/spin-down.nix
../../modules/btrfs-scrub.nix
../../modules/btrfs-mount-options.nix
];
networking.hostName = "yodaYoga";
boot.initrd.luks.devices."luks-a8521407-e25b-4f26-8e7a-a56fcbfd2e35".allowDiscards = true;
yoda.btrfs-scrub = ["/"];
yoda.btrfsFileSystems = ["/"];
#yoda.btrfsMounts = yoda.btrfsFileSystems;
boot.kernelParams = [];

View File

@ -80,24 +80,6 @@
MaxFileSec=7day
'';
# BTRFS mount options.
#
# compress=
# `nixos-generate-config` does not detect mount options, so we add them here.
# https://nixos.wiki/wiki/Btrfs#Compression
#
# noatime
# Under read intensive work-loads, specifying noatime significantly improves performance because no new access time information needs to be written.
# https://man.archlinux.org/man/btrfs.5#NOTES_ON_GENERIC_MOUNT_OPTIONS
#
# commit=
# The number of seconds between periodic commits to the filesystem. This is 30 seconds by default. Increasing this value reduces the frequency of periodic writes which can reduce wear on the disk. However, this also increases the risk of data loss during the event of an untimely crash.
# https://www.jwillikers.com/btrfs-mount-options
#
fileSystems = {
"/".options = [ "compress=zstd" "noatime" "commit=120" ];
};
nix.settings.auto-optimise-store = true;
# https://nixos.wiki/wiki/Storage_optimization#Automation

View File

@ -0,0 +1,43 @@
# BTRFS mount options.
#
# compress=
# `nixos-generate-config` does not detect mount options, so we add them here.
# https://nixos.wiki/wiki/Btrfs#Compression
#
# noatime
# Under read intensive work-loads, specifying noatime significantly improves performance because no new access time information needs to be written.
# https://man.archlinux.org/man/btrfs.5#NOTES_ON_GENERIC_MOUNT_OPTIONS
#
# commit=
# The number of seconds between periodic commits to the filesystem. This is 30 seconds by default. Increasing this value reduces the frequency of periodic writes which can reduce wear on the disk. However, this also increases the risk of data loss during the event of an untimely crash.
# https://www.jwillikers.com/btrfs-mount-options
#
{ lib, config, options, pkgs, modulesPath, ... }:
with lib;
let
cfg = config.yoda.btrfsMounts;
in
{
options = {
yoda.btrfsMounts = mkOption {
type = types.listOf types.path;
default = config.yoda.btrfsFileSystems;
example = ["/" "/mnt/data"];
description = ''
List containing each BTRFS mountpoint.
If each BTRFS filesystem is only mounted once, this can be left at its default value.
'';
};
};
config = mkIf (length cfg > 0) {
# For each element (e.g. "/") in `cfg` create this config:
# fileSystems."/".options = [ "compress=zstd" "noatime" "commit=120" ];
fileSystems = builtins.listToAttrs (builtins.map (fs: {
name = fs;
value = { options = [ "compress=zstd" "noatime" "commit=120" ]; };
}) cfg);
};
}

View File

@ -17,11 +17,11 @@
{ lib, config, options, pkgs, modulesPath, ... }:
with lib;
let
cfg = config.yoda.btrfs-scrub;
cfg = config.yoda.btrfsFileSystems;
in
{
options = {
yoda.btrfs-scrub = mkOption {
yoda.btrfsFileSystems = mkOption {
type = types.listOf types.path;
default = ["/"];
example = ["/" "/mnt/data"];