Last active
March 27, 2025 21:38
-
-
Save blurgyy/0d559e6bb9f20de46f61938539b9cd74 to your computer and use it in GitHub Desktop.
Enable zram and larger nix store in a NixOS live ISO environment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Run this as root | |
zram_size=2G | |
if [[ "$#" -gt 0 ]]; then | |
zram_size="$1" | |
fi | |
# Enable zram swap | |
# REF: <https://wiki.archlinux.org/title/Improving_performance#zram_or_zswap> | |
if ! lsmod | grep -q zram; then | |
modprobe zram | |
echo lz4 >/sys/block/zram0/comp_algorithm | |
echo "$zram_size" >/sys/block/zram0/disksize | |
fi | |
if ! swapon --show=NAME --noheadings | grep -q /dev/zram0; then | |
mkswap /dev/zram0 | |
swapon --priority 100 /dev/zram0 | |
fi | |
# Remount tmpfs for larger nix store | |
mount -oremount,size=100% /nix/.rw-store | |
# Mount nixos if previously installed | |
root_part=/dev/disk/by-label/nixos-root | |
boot_part=/dev/disk/by-label/nixos-boot | |
esp_part=/dev/disk/by-label/nixos-esp | |
if [[ -e "$root_part" ]]; then | |
mount_opt="" | |
if [[ "$(lsblk -no FSTYPE "$root_part")" == btrfs ]]; then | |
mount_opt=compress-force=zstd:3,noatime | |
fi | |
mount -o"$mount_opt" "$root_part" /mnt | |
mkdir -p /mnt/boot | |
fi | |
if [[ -e "$boot_part" ]]; then | |
mount "$boot_part" /mnt/boot | |
elif [[ -e "$esp_part" ]]; then | |
mount "$esp_part" /mnt/boot | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment