From 5cf6554f0e979bd3c2347d6a76d160af24464297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Eug=C3=AAnio?= Date: Sun, 7 Aug 2022 13:59:05 -0300 Subject: [PATCH] add swapfile --- system/monolith-hardware-configuration.nix | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/system/monolith-hardware-configuration.nix b/system/monolith-hardware-configuration.nix index 62780aa..a11d2e6 100644 --- a/system/monolith-hardware-configuration.nix +++ b/system/monolith-hardware-configuration.nix @@ -47,7 +47,6 @@ fsType = "btrfs"; options = [ "subvol=@torrents" "nofail" ]; }; - swapDevices = [ ]; services.udev.extraRules = '' ACTION=="add", SUBSYSTEM=="pci", DRIVER=="pcieport", ATTR{power/wakeup}="disabled" ''; @@ -60,4 +59,26 @@ hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; networking.hostName = "monolith"; # Define your hostname. + + # swap + systemd.services = { + create-swapfile = { + serviceConfig.Type = "oneshot"; + wantedBy = [ "swap-swapfile.swap" ]; + script = '' + ${pkgs.coreutils}/bin/truncate -s 0 /swap/swapfile + ${pkgs.e2fsprogs}/bin/chattr +C /swap/swapfile + ${pkgs.btrfs-progs}/bin/btrfs property set /swap/swapfile compression none + ''; + }; + }; + fileSystems."/swap" = { + device = "/dev/disk/by-label/BTRFS_ROOT"; + fsType = "btrfs"; + options = [ "subvol=swap" ]; # Note these options effect the entire BTRFS filesystem and not just this volume, with the exception of `"subvol=swap"`, the other options are repeated in my other `fileSystem` mounts + }; + swapDevices = [{ + device = "/swap/swapfile"; + size = (1024 * 16) + (1024 * 2); # RAM size + 2 GB + }]; }