-
-
Save knedlsepp/b85287226586f53675bcd12e91e1c1fe to your computer and use it in GitHub Desktop.
Some useful aliases for installing and working with NixOS
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 $SHELL | |
alias lsblk="lsblk -o MODEL,VENDOR,NAME,LABEL,SIZE,MOUNTPOINT,FSTYPE" | |
alias gramps="nix-env -p /nix/var/nix/profiles/system --list-generations" | |
alias nixos-rebuild="nixos-rebuild -j 6 --cores 8" | |
# | |
# -j is how many "jobs" or simultaneous computational processes run in tandem | |
# --cores is how many CPU cores you want to use | |
# How do you get these values? `cat /proc/cpuinfo` and look at the number of | |
# returned "CPUs". They're zero indexed, so if you get the last one as object | |
# number seven (7), you have 8 cores. | |
# From there, I just subtract a few to give the operating system "breathing | |
# room" from a cpu throughput perspective and boom, max number of jobs. | |
# | |
# NOTES ON INSTALLING NIXOS | |
# | |
# For AMD graphics cards, DO NOT use the "ati_unfree" driver mentioned in the docs; | |
# it's over a year old and cost me 14+ hours of my life I'll never get back. Instead, | |
# use ONLY the "amdgpu-pro" driver. (For now, who knows when that'll next change?) | |
# | |
# START in UEFI mode. Always. Disable Windows System Protection nonsense in your BIOS | |
# first, just in case. | |
# | |
# AM I IN UEFI MODE? | |
# ls /sys/firmware/ | |
# # if "efi" is a directory that shows up, you're in efi mode | |
# | |
# HOW TO PREP A GIVEN DEVICE FOR INSTALLATION | |
# Verify you've got the right one with the lsblk alias above. | |
# Then, use `cgdisk` -- NOTE THE LETTER 'G' HERE, IT'S VITAL -- to partition | |
# it as follows: | |
# | |
# (assuming you want to install on /dev/sda) | |
# /dev/sda1 EFIBOOT 512M (partition code: EF00) | |
# /dev/sda2 linuxswap {SOME_VALUE} (partition code: 8200) | |
# /dev/sda3 {SOME_LABEL} {SOME_VALUE} (partition code: 8300) | |
# | |
# Values and how to get them: | |
# For my swap, I like to match the swap partition to the same amount of system | |
# memory I have, *unless I have an obscene amount of system memory*. In the case | |
# of one machine I tried this on (a physical desktop I'm using as my daily driver) | |
# it had a whopping 32GB of memory. Now, if I've filled THAT MUCH, and I haven't | |
# something's already wrong. But rolling with NO swap? Ehh...that just don't feel | |
# right, kinda like driving drunk without a seatbelt. So in this case I split the | |
# difference down the middle - 16GB. Easy peasy. | |
# | |
# As for the EFIBOOT partition, I feel half a gig is about right. Gives you room | |
# to grow, copy kernels and raise all kinds of hell without wasting too much space | |
# on your precious SSD. | |
# | |
# Which brings us to /dev/sda3. This can be labeled anything you want (my early | |
# attempts were things like "fuzzywuzzy" and "krypton"), but DON'T name it "nixos". | |
# Why? Because that's the name/label of your installer "LiveCD!". Meaning anything | |
# mounting **by label** might get the two confused. Not cool. | |
# | |
# As for size, I just take whatever `cgdisk` gives me as the first and last contiguous | |
# sector/node values such that I have these literally in **SEQUENTIAL ORDER ON THE DISK | |
# BY SECTOR** _and_ **the last partition goes to the last node, filling the disk.** | |
# No wasted space. | |
# | |
# FORMATTING THE FILESYSTEMS | |
# | |
# After writing the partition table to the disk, and verifying it again with my `lsblk` | |
# shortcut above, you can now format the partitions. | |
# | |
# mkfs.fat -F 32 -n EFIBOOT /dev/sda1 | |
# mkswap -L linuxswap /dev/sda2 | |
# mkfs.ext4 -L YOUR-SYSTEM-NAME /dev/sda3 | |
# | |
# Once this is done you can mount the filesystem according to its proper pre-install layout. | |
# | |
# MOUNTING. THE RIGHT WAY. | |
# | |
# mkdir /mnt # might already exist, no problem; just make sure it's empty | |
# mount /dev/disk/by-label/YOUR-SYSTEM-NAME /mnt -o noatime,discard # omit discard if NOT solid state | |
# mkdir /mnt/boot | |
# mount /dev/disk/by-label/EFIBOOT /mnt/boot # this is your EFI boot partition | |
# swapon /dev/sda2 | |
# | |
# You now have a properly laid-out system mounted. Verify with `df -H`. You want: | |
# /dev/sda1 => UEFI boot partition, blank, FAT32 formatted (nothing else works) mounted at /mnt/boot | |
# /dev/sda2 => Linux swap partition; ensure that it's actually running just in case the build gets | |
# hairy by running "free -m". Is there a line reading "swap" at the bottom? Yes? Good. | |
# /dev/sda3 => Linux EXT4 filesystem mounted at /mnt. It should be blank at this point (maybe a | |
# lost+found dir but nothing else) | |
# | |
# Finally. You're ready to run the hardware config generation script. | |
# | |
# GENERATE THE BASE CONFIGURATION | |
# | |
# This handy-dandy command will jot down information about your disks **AS THEY'RE PRESENTLY MOUNTED** | |
# which is why we went to the trouble of doing it "by label" and with the right mount options earlier. | |
# It also specifies what kernel modules you might need during systemd's UEFI boot process. And other | |
# basic stuff. Then it generates the all-important /etc/nixos/configuration.nix file. | |
# | |
# Run this: | |
# | |
# nixos-generate-config --root /mnt | |
# | |
# You should now have two files in /mnt/etc/nixos/ | |
# configuration.nix | |
# hardware-configuration.nix | |
# | |
# DON'T TOUCH THE HARDWARE CONFIGURATION FILE, DAMN IT! Trust me on this. Don't. Do. It. | |
# Instead, hax up that configuration.nix file to your liking. Now you see about installing the OS. | |
# | |
# INSTALLATION. FINALLY. | |
# | |
# Run the following to _attempt_ to install. Warning: Every configuration mistake you make, | |
# God kills a kitten. | |
# | |
# nixos-install -j 6 --cores 8 --root /mnt --show-trace | |
# | |
# Explanations of -j and --cores are the same as above. --root /mnt just tells it where you want your | |
# fs root to be in the end. --show-trace is important here, especially when you haven't done this before, | |
# because the options for settings in configuration.nix aren't well documented (if at all), wildly | |
# inconsistent, and frequently conflict one another. You'll have to weed through these one-by-one. | |
# Press on and push through the pain. | |
# | |
# Finally, you _should_ get a working build. Run echo $? and if that's zero, run the simple command, reboot. | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment