Skip to content

gerwin3/nixcfg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nixcfg

Usage

I keep my nixcfg repository separate from /etc/nixos. After making changes, the apply.sh script copies the config into /etc/nixos and rebuilds the system.

./apply

To update the system, use:

./apply --update

This will apply the configuration, as well as updating the lock file.

Known Issues

  • On laptop, swaylock does not activate after closing the lid and opening again even though swayidle is configured to do so via before-sleep.
  • The NVIDIA open driver does not load correctly which causes CUDA to error with code 999. The workaround for now is to manually call sudo modprobe nvidia_uvm before using CUDA which fixes the issue until next boot.

Installation

First, create a bootable medium from the minimal NixOS installation image, and boot from it on the target machine. Then follow the installation steps:

  1. Clone this repository:

    git clone https://github.com/gerwin3/nixcfg.git
  2. Partition the disks as needed. This configuration expects the following partitions to exist:

    • A nix partition mounted on /nix.
    • A persist partition mounted on /persist.
    • A transient partition (like tmpfs) on /.

    The recommended setup is to create a LUKS disk, then create a btrfs filesystem on it and configure the nix and persist partitions as btrfs subvolumes.

    These are (roughly) the steps needed to partition the disk and create the necessary file systems:

    # Partition a primary disk and a 2GB boot partition.
    parted /dev/nvme0n1 -- mklabel gpt
    parted /dev/nvme0n1 -- mkpart root 2048MB 100%
    parted /dev/nvme0n1 -- mkpart ESP fat32 1MB 2048MB
    parted /dev/nvme0n1 -- set 2 esp on
    
    # Format and the boot partition (from NixOS installation guide).
    mkfs.fat -F 32 -n boot /dev/nvme0n1p2
    mkdir -p /mnt/boot
    
    # Format LUKS encrypted partition, and create btrfs filesystem inside it.
    cryptsetup luksFormat /dev/nvme0n1p1
    cryptsetup open /dev/nvme0n1p1 root
    mkfs.btrfs /dev/mapper/root
    mount /dev/mapper/root /mnt
    # Create subvolumes for nix and persistence, then mount them.
    btrfs subvolume create /mnt/nix
    btrfs subvolume create /mnt/persist
    # Unmount /mnt here since we only need /mnt/boot, /mnt/nix and /mnt/persist
    umount /mnt
    
    # Mount all disks
    mount -o umask=077 /dev/disk/by-label/boot /mnt/boot
    mount -o subvol=nix /dev/mapper/root /mnt/nix
    mount -o subvol=persist /dev/mapper/root /mnt/persist

Note

Refer to the NixOS installation guide UEFI section for more information.

  1. Generate the hardware configuration with nixos-generate-config or use one of the pre-defined ones. Either way, make sure to modify the configuration to suit your needs.

    Edit flake.nix under nixConfigurations and add a new configuration. Import the preffered hardware configuration there.

    The tmpfs file system entry needs to be added manually, for example:

    fileSystems."/" = {
      device = "none";
      fsType = "tmpfs";
      options = [ "defaults" "size=25G" "mode=755" ];
      neededForBoot = true;
    };

    In the example above, the tmpfs file system is 25GB in size. Make sure this number is lower than the available RAM in the system.

    This is also the time to add other useful stuff:

    kernelPackages = pkgs.linuxPackages_latest;
    loader.efi.canTouchEfiVariables = true;

    Also for persistence it is necessary to add neededForBoot attributes to each of the three volumes: nix, persistence and tmpfs:

    fileSystems."/".neededForBoot = true;
    fileSystems."/nix".neededForBoot = true;
    fileSystems."/persist".neededForBoot = true;

    Refer to framework-13-Ryzen.nix for a good starting point.

Note

It is advisable to temporarily comment out the private modules such as wireguard.nix and re-add them after installation when git credentials have been set up.

  1. Generate your user password:

    echo "Enter password for main user:" && \
        mkdir secrets && \
        mkpasswd -m yescrypt | tr -d '\n' > secrets/password
  2. Create configuration directories:

    sudo mkdir -p /mnt/persist/etc/nixos && \
        sudo cp -r * /mnt/persist/etc/nixos
  3. Perform installation:

    Put the name of the configuration (chosen in step 3) after the hash.

    sudo nixos-install --no-root-passwd --flake /mnt/persist/etc/nixos#system && \
        sudo reboot now

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published