Partitions layout advice for NixOS during installation

Hello,

I ordered a new hard disk drive for my laptop, I should be receiving it tomorrow.
I was using a Samsung EVO 860 since ~5 years and I ordered the Samsung EVO 870, same size which is 500Gb.

I didn’t reinstalled the NixOS on top of my old disk because the partition were using the JFS type and I’d like to go back to EXT4 and keep my existing data, without transferring everything somewhere else.

In order to have a hard disk drive in good health, it is recommended to partition it in a smart way.
Therefore, I have a layout in mind, do you think you could help me and give me your point of view?

Here it is:

  • /boot partition: 1Gb
  • /nix partition: 100Gb (documentation for this)
  • /home partition: 300Gb
  • / partition: 91Gb
  • swap partition 8Gb

Do you think this layout is fine? Would you recommend something else?

Thanks!

1 Like
  • why separate /nix partition?
  • you probably don’t need a separate /home partition, unless you plan to use several distros on the same computer (do you?)
  • if you are dead set on separate partitions, perhaps create them more flexibly (as LVM volumes or ZFS pools)
  • I’m not sure good modern SSDs actually care, health-wise, how you partition them (except possibly for the alignment, but modern partitioning tools take care of that for you)
  • depending on the amount of RAM, 8Gb may not be enough swap if you want your computer to be able to hibernate
1 Like
  • why separate /nix partition?

Apparently, it’s better to separate partition where read/write happens a lot of time (during updates). I remember I saw that in an article where it explained that it is better for the lifespan of the SSD.

  • you probably don’t need a separate /home partition, unless you plan to use several distros on the same computer (do you?)

No I only plan to use NixOS.

  • if you are dead set on separate partitions, perhaps create them more flexibly (as LVM volumes or ZFS pools)

No, I want something simple. I don’t want to dive into LVM and ZFS.

  • I’m not sure good modern SSDs actually care, health-wise, how you partition them

I will try to find this article if I can.

  • depending on the amount of RAM, 8Gb may not be enough swap if you want your computer to be able to hibernate

Good point, I will increase it.

It helps mitigating the “out of inodes” problem one might run into easily when using Nix+Ext4.

I currently have a LVM+ext4 setup, with which I am not 100% happy with:

  • /: 1 GB
  • /boot: 1 GB
  • /nix: 100 GB
  • /home: 400 GiB
  • /var/lib/docker: 50 GiB

And I am eager to add more data-drives as needed.

In the current setup there are still 400 GB of space left in the LVM to get allocated.

1 GB for / partition ?!

Yes, I try to avoid having anything on / that isn’t a symlink.

I’d note that /nix can be mounted noatime :slight_smile:

Partitioning is always subjective. I like a separate /home, it’s useful for disaster recovery, but it is indeed a bit superfluous on nix hosts (since almost everything else in / will be controlled anyway). Nonetheless, it’s pretty harmless.

Other than that, your / is indeed a big for NixOS - most files that traditionally go there should be kept in /nix. 1GB is a bit little, but I’ve not found myself needing even 20GB. /boot is also on the big end, unless you intend to keep a lot of kernels around.

I also resonate with the LVM suggestion. It’s nice to be able to change your mind without a lot of effort in the future, or if you need to add extra drives when you eventually run out of /home space. LVM is a lot less complex than it might seem initially!

Also see Erase your darlings: immutable infrastructure for mutable systems - Graham Christensen, i.e. root-in-tmpfs, which I’d consider the ultimate in terms of NixOS file system management, though it’s well into complex territory.

Edit: Should probably have linked my LVM setup commands/instructions while I’m at it, which document exactly what I do.

I have a 1TB NVME with this partition scheme:

  • /boot: 1GB fat32
  • swap: 13GB
  • /: 987GB BTRFS

Inside the / I have this scheme of subvolumes:

  • @: /
  • @home: /home
  • @nix: /nix
  • @log: /var/log

All subvolumes are mount with compression (compress-force=zstd:1) which helps with disk space. Subvolumes is a very good idea because a subvolume can occupy all space in disk and if I need to reinstall the system I can the /home.

2 Likes

Hello,

I did it and it works well.

Here’s the output of df -h:

root@x260 / (master)# df -h                                                                                                                                                                                          
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        795M     0  795M   0% /dev
tmpfs           7.8G   47M  7.8G   1% /dev/shm
tmpfs           3.9G  8.5M  3.9G   1% /run
tmpfs           7.8G  528K  7.8G   1% /run/wrappers
/dev/sda3        98G  5.3G   88G   6% /
/dev/sda4        49G   21G   27G  44% /nix
/dev/sda2       295G   61G  220G  22% /home
/dev/sda1      1022M   42M  981M   5% /boot
tmpfs           1.6G  5.1M  1.6G   1% /run/user/1000

I guess at some point I will shrink the size of /. Right now, the space is mostly used by docker, maybe I should have created a partition for /var.