From 3952094233f225eac2ed58f679bf77777ecceae8 Mon Sep 17 00:00:00 2001 From: Daniel Langbein Date: Mon, 28 Aug 2023 15:50:16 +0200 Subject: [PATCH] BTRFS swap file --- README.md | 13 +++++++++++++ yodaTab/hardware-configuration.nix | 8 +++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index af82c9e..62140ff 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,19 @@ Use the corresponding branch: # TODO (!) ``` +## BTRFS Swap file + +* https://nixos.wiki/wiki/Btrfs#Swap_file +* https://wiki.archlinux.org/title/btrfs#Swap_file + +Summary: + +* Create subvolume `@swap` directly below top-level subvolume. +* Mount at `/swap` +* Create swapfile: `sudo btrfs filesystem mkswapfile --size 8g --uuid clear /swap/swapfile` +* Regenerate hardware-configuration: `sudo nixos-generate-config --dir yodaTab` +* Add `swapDevices = [ { device = "/swap/swapfile"; } ];` to hardware configuration and run `nixos-rebuild switch` (see above). + ## Automount Encrypted Drive * Generate and add keyfile to LUKS device diff --git a/yodaTab/hardware-configuration.nix b/yodaTab/hardware-configuration.nix index 9a387c0..05e62ac 100644 --- a/yodaTab/hardware-configuration.nix +++ b/yodaTab/hardware-configuration.nix @@ -35,7 +35,13 @@ boot.initrd.luks.devices."512gb".device = "/dev/disk/by-uuid/03d4ac28-2c81-463e-b615-fb623d40b6fa"; - swapDevices = [ ]; + fileSystems."/swap" = + { device = "/dev/disk/by-uuid/f87e6b3c-12f2-4fda-92b3-06b07bdad58f"; + fsType = "btrfs"; + options = [ "subvol=@swap" ]; + }; + + swapDevices = [ { device = "/swap/swapfile"; } ]; # Enables DHCP on each ethernet and wireless interface. In case of scripted networking # (the default) this is the recommended approach. When using systemd-networkd it's