2023-12-02 17:38:00 +00:00
# zfs docs:
# - <https://nixos.wiki/wiki/ZFS>
# - <repo:nixos/nixpkgs:nixos/modules/tasks/filesystems/zfs.nix>
#
2024-01-11 00:20:52 +00:00
# zfs check health: `zpool status`
#
2023-12-02 17:38:00 +00:00
# zfs pool creation (requires `boot.supportedFilesystems = [ "zfs" ];`
# - 1. identify disk IDs: `ls -l /dev/disk/by-id`
# - 2. pool these disks: `zpool create -f -m legacy pool raidz ata-ST4000VN008-2DR166_WDH0VB45 ata-ST4000VN008-2DR166_WDH17616 ata-ST4000VN008-2DR166_WDH0VC8Q ata-ST4000VN008-2DR166_WDH17680`
# - legacy documented: <https://superuser.com/questions/790036/what-is-a-zfs-legacy-mount-point>
#
# import pools: `zpool import pool`
# show zfs datasets: `zfs list` (will be empty if haven't imported)
# show zfs properties (e.g. compression): `zfs get all pool`
# set zfs properties: `zfs set compression=on pool`
2022-06-24 04:21:01 +00:00
{ . . . }:
2022-04-27 06:38:39 +00:00
{
2023-12-02 17:38:00 +00:00
# hostId: not used for anything except zfs guardrail?
# [hex(ord(x)) for x in 'serv']
networking . hostId = " 7 3 6 5 7 2 7 6 " ;
boot . supportedFilesystems = [ " z f s " ] ;
# boot.zfs.enabled = true;
boot . zfs . forceImportRoot = false ;
# scrub all zfs pools weekly:
services . zfs . autoScrub . enable = true ;
2024-01-11 00:20:52 +00:00
boot . extraModprobeConfig = ''
# ZFS likes to use half the ram for its own cache and let the kernel push everything else to swap.
# so, reduce its cache size
# see: <https://askubuntu.com/a/1290387>
# see: <https://serverfault.com/a/1119083>
# see: <https://openzfs.github.io/openzfs-docs/Performance%20and%20Tuning/Module%20Parameters.html#zfs-arc-max>
# for all tunables, see: `man 4 zfs`
# to update these parameters without rebooting:
# - `echo '4294967296' | sane-sudo-redirect /sys/module/zfs/parameters/zfs_arc_max`
options zfs zfs_arc_max = 4294967296
'' ;
2023-12-02 17:38:00 +00:00
# to be able to mount the pool like this, make sure to tell zfs to NOT manage it itself.
# otherwise local-fs.target will FAIL and you will be dropped into a rescue shell.
# - `zfs set mountpoint=legacy pool`
# if done correctly, the pool can be mounted before this `fileSystems` entry is created:
# - `sudo mount -t zfs pool /mnt/persist/pool`
2023-12-07 08:57:26 +00:00
fileSystems . " / m n t / p o o l " = {
2023-12-02 17:38:00 +00:00
device = " p o o l " ;
fsType = " z f s " ;
} ;
# services.zfs.zed = ... # TODO: zfs can send me emails when disks fail
2023-12-03 00:58:49 +00:00
sane . programs . sysadminUtils . suggestedPrograms = [ " z f s " ] ;
2023-12-02 17:38:00 +00:00
2023-12-07 08:57:26 +00:00
sane . persist . stores . " e x t " = {
origin = " / m n t / p o o l / p e r s i s t " ;
storeDescription = " e x t e r n a l H D D s t o r a g e " ;
2024-02-23 03:36:31 +00:00
defaultMethod = " b i n d " ; #< TODO: change to "symlink"?
2023-12-07 08:57:26 +00:00
} ;
2023-12-02 17:38:00 +00:00
2023-08-11 06:53:47 +00:00
# increase /tmp space (defaults to 50% of RAM) for building large nix things.
# even the stock `nixpkgs.linux` consumes > 16 GB of tmp
fileSystems . " / t m p " . options = [ " s i z e = 3 2 G " ] ;
2022-06-29 08:17:53 +00:00
fileSystems . " / n i x " = {
2022-11-29 02:20:18 +00:00
device = " / d e v / d i s k / b y - u u i d / c c 8 1 c c a 0 - 3 c c 7 - 4 d 8 2 - a 0 0 c - 6 2 4 3 a f 3 e 7 7 7 6 " ;
2022-06-29 08:17:53 +00:00
fsType = " b t r f s " ;
2022-11-29 02:20:18 +00:00
options = [
" c o m p r e s s = z s t d "
" d e f a u l t s "
] ;
2022-06-29 08:17:53 +00:00
} ;
2022-05-17 01:58:12 +00:00
fileSystems . " / b o o t " = {
2022-11-29 02:20:18 +00:00
device = " / d e v / d i s k / b y - u u i d / 6 E E 3 - 4 1 7 1 " ;
2022-05-17 01:58:12 +00:00
fsType = " v f a t " ;
} ;
2022-11-29 21:54:33 +00:00
# slow, external storage (for archiving, etc)
2023-12-07 08:57:26 +00:00
fileSystems . " / m n t / u s b - h d d " = {
2022-11-29 21:54:33 +00:00
device = " / d e v / d i s k / b y - u u i d / a a 2 7 2 c f f - 0 f c c - 4 9 8 e - a 4 c b - 0 d 9 5 f b 6 0 6 3 1 b " ;
fsType = " b t r f s " ;
options = [
" c o m p r e s s = z s t d "
" d e f a u l t s "
] ;
} ;
2023-12-07 08:57:26 +00:00
sane . fs . " / m n t / u s b - h d d " . mount = { } ;
2023-01-04 02:15:43 +00:00
2024-03-05 18:39:23 +00:00
sane . persist . sys . byStore . plaintext = [ {
2024-03-05 18:44:30 +00:00
path = " / v a r / m e d i a " ;
2024-03-05 18:39:23 +00:00
method = " b i n d " ; #< this HAS to be `bind` if we're going to persist the whole thing but create subdirs, as below.
user = " c o l i n " ;
group = " m e d i a " ;
mode = " 0 7 5 5 " ;
} ] ;
2024-03-05 18:44:30 +00:00
sane . fs . " / v a r / m e d i a / a r c h i v e " . dir = { } ;
2024-02-23 08:14:27 +00:00
# this is file.text instead of symlink.text so that it may be read over a remote mount (where consumers might not have any /nix/store/.../README.md path)
2024-03-05 18:44:30 +00:00
sane . fs . " / v a r / m e d i a / a r c h i v e / R E A D M E . m d " . file . text = ''
2023-09-07 02:21:50 +00:00
this directory is for media i wish to remove from my library ,
but keep for a short time in case i reverse my decision .
treat it like a system trash can .
'' ;
2024-03-05 18:44:30 +00:00
sane . fs . " / v a r / m e d i a / B o o k s " . dir = { } ;
sane . fs . " / v a r / m e d i a / B o o k s / A u d i o b o o k s " . dir = { } ;
sane . fs . " / v a r / m e d i a / B o o k s / B o o k s " . dir = { } ;
sane . fs . " / v a r / m e d i a / B o o k s / V i s u a l " . dir = { } ;
sane . fs . " / v a r / m e d i a / c o l l e c t i o n s " . dir = { } ;
sane . fs . " / v a r / m e d i a / d a t a s e t s " . dir = { } ;
sane . fs . " / v a r / m e d i a / f r e e l e e c h " . dir = { } ;
sane . fs . " / v a r / m e d i a / M u s i c " . dir = { } ;
sane . fs . " / v a r / m e d i a / P i c t u r e s " . dir = { } ;
sane . fs . " / v a r / m e d i a / V i d e o s " . dir = { } ;
sane . fs . " / v a r / m e d i a / V i d e o s / F i l m " . dir = { } ;
sane . fs . " / v a r / m e d i a / V i d e o s / S h o w s " . dir = { } ;
sane . fs . " / v a r / m e d i a / V i d e o s / T a l k s " . dir = { } ;
2024-02-23 08:14:27 +00:00
# this is file.text instead of symlink.text so that it may be read over a remote mount (where consumers might not have any /nix/store/.../README.md path)
2023-09-07 02:21:50 +00:00
sane . fs . " / v a r / l i b / u n i n s a n e / d a t a s e t s / R E A D M E . m d " . file . text = ''
this directory may seem redundant with ../media/datasets. it isn't .
this directory exists on SSD , allowing for speedy access to specific datasets when necessary .
the contents should be a subset of what's in ../media/datasets.
'' ;
2023-01-04 02:15:43 +00:00
# make sure large media is stored to the HDD
2023-11-13 02:26:46 +00:00
sane . persist . sys . byStore . ext = [
2023-01-04 02:15:43 +00:00
{
user = " c o l i n " ;
group = " u s e r s " ;
mode = " 0 7 7 7 " ;
2024-03-05 18:44:30 +00:00
path = " / v a r / m e d i a / V i d e o s " ;
2023-01-04 02:15:43 +00:00
}
{
user = " c o l i n " ;
group = " u s e r s " ;
mode = " 0 7 7 7 " ;
2024-03-05 18:44:30 +00:00
path = " / v a r / m e d i a / f r e e l e e c h " ;
2023-01-04 02:15:43 +00:00
}
2023-07-05 09:00:41 +00:00
{
user = " c o l i n " ;
group = " u s e r s " ;
2024-03-05 18:39:23 +00:00
mode = " 0 7 7 5 " ;
path = " / v a r / l i b / u n i n s a n e / d a t a s e t s " ;
2023-07-05 09:00:41 +00:00
}
2023-01-04 02:15:43 +00:00
] ;
2022-11-29 21:54:33 +00:00
2022-06-29 10:29:45 +00:00
# btrfs doesn't easily support swapfiles
# swapDevices = [
# { device = "/nix/persist/swapfile"; size = 4096; }
# ];
# this can be a partition. create with:
# fdisk <dev>
# n
# <default partno>
# <start>
# <end>
# t
# <partno>
# 19 # set part type to Linux swap
# w # write changes
# mkswap -L swap <part>
2022-11-29 02:20:18 +00:00
# swapDevices = [
# {
# label = "swap";
# # TODO: randomEncryption.enable = true;
# }
# ];
2022-04-27 06:38:39 +00:00
}