Resizing my Nix OS partition for LFS

Hey all!

I have NixOS installed on my laptop right now (I installed it 1 or 2 years ago using the graphical installer).

I now want to follow through the Linux From Scratch book. To achieve this, I need to create a new 10GB or so partition, but the problem is that when I installed Nix OS, I installed it so that it occupies my entire disc.

I suppose what I have to do now is to shrink my root partition (I only have 1 root and 1 boot partition), but because there is stuff declared on my hardware-configuration.nix, I am not sure if I can just go ahead and do it.

My hardware file is shown below:

# Do not modify this file!  It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations.  Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }:

{
  imports =
    [ (modulesPath + "/installer/scan/not-detected.nix")
    ];

  boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usb_storage" "sd_mod" "rtsx_pci_sdmmc" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ "kvm-intel" ];
  boot.extraModulePackages = [ ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/1a97cc33-ed66-45a1-bd7f-6c31224cde48";
      fsType = "ext4";
    };

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/B801-CD48";
      fsType = "vfat";
    };

  swapDevices = [ ];

  # 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
  # still possible to use this option, but it's recommended to use it in conjunction
  # with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
  networking.useDHCP = lib.mkDefault true;
  # networking.interfaces.eno2.useDHCP = lib.mkDefault true;
  # networking.interfaces.wlo1.useDHCP = lib.mkDefault true;

  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
  hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

So. my question is, should I just shrink my root partition by like 20/30 GB, and then re-run nixos-generate-config, and this will pick up all the changed that I made? Or is there a better way to do this?

Thanks, and sorry if this is a noob question.

If all you do is shrink the partition, there’s no changes that nixos-generate-config needs to pick up; your partition will still have the same UUID and NixOS doesn’t care what it’s size is.

1 Like

Ahhh I see. Somehow I thought the UUID would change, and I was afraid I would break something. Thank you!

It is, but if noob questions were banned, I didn’t hear about it (and this forum would probably be dead). But to be clear, the only time the uuid should change is if you recreated the filesystem, and tbh I don’t even run nixos-generate-config ever after the first install - so I don’t treat hardware-configuration.nix as a special file, I do edit my FS configuration directly/manually if hardware gets switched out or so on.

1 Like