Skip to content

NixOS, nix-darwin, and Home Manager configurations

Notifications You must be signed in to change notification settings

cor/nixos-config

Repository files navigation

nixos-config

My NixOS, nix-darwin and Home Manager configurations.

Structure

I use NixOS inside of a OrbStack on a M3 Mac running macOS. In addition to this, I use nix-darwin to configure macOS with nix-darwin. Both of these setups also use Home Manager. These configurations share the same modules/ and home-modules/.

Modules

There are two kinds of modules:

  1. modules/, which define NixOS or nix-darwin level options.
  2. home-modules/, which define Home Manager options on both NixOS and macOS.

Configuration generating functions

The modules mentioned above are imported inside of two configuration generation functions:

  1. ./nixos.nix, this function generates a nixosConfiguration
  2. ./darwin.nix, this function generates a darwinConfiguration

These fucntions are used in ./flake.nix's nixosConfigurations and darwinConfigurations

How to fork this configuration for your own usage

NOTE: These instructions are out of date

  1. Do a project-wide search of my username, cor and replace it with your_username. Be careful not to replace things that are not my username, such as "core".
  2. In ./nixos.nix, replace the value of hashedPassword with one you've generated with mkpasswd -m sha-512 See here for more info.
  3. In ./programs/git.nix, change userName and extraConfig.github.user to your GitHub username. Also change signing.key to the public GPG key you use for your GitHub account.

macOS Nix config with nix-darwin

NOTE: macOS Nix config is not required for setting up the NixOS VM. For instructions on this, check the next section

Make sure not to install Homebrew or Xcode Command Line Tools!

  1. Do a clean install macOS, deny analytics.
  2. Install Nix on macOS with the installer
  3. In ~, execute nix-shell -p git --command "git clone https://github.com/cor/nixos-config"
  4. Install nix-darwin with the nix-darwin installer.
  5. Restart Terminal.app
  6. sudo mv /etc/nix/nix.conf /etc/nix/nix.conf.original
  7. In ~/nixos-config, execute nix-shell --no-sandbox -p cmake --command "make switch-darwin"
  8. Download 1Password and browser extension
  9. From 1Password, download SSH keys: id_ed25519 and id_ed25519.pub. Move them to ~/.ssh~
  10. From 1Password, download GPG keys: secret-key-backup.asc. Import them with: gpg --import ./secret-key-backup.asc. Afterwards, run rm ./secret-key-backup.asc
  11. From 1Password, download GPG trust-db-backup.txt. Import them with: gpg --import-ownertrust < ./trustdb-backup.txt, Afterwards, run rm ./trustdb-backup.txt
  12. Open Safari, go to Settings > Search > Search Engine. Select DuckDuckGo. Go to Settings > Advanced > Smart Search Field, click "Show full ewbsite address". Go to Settings > Advanced, at the bottom click "Show Develop menu in menu bar"
  13. Open Settings.app, Go to Desktop & Dock > Show recent applications in Dock and disable it
  14. Remove all apps from dock, turn hide dock on

NixOS VM using UTM

  1. Install UTM from the Mac App Store
  2. Download a minimal 64-bit ARM ISO from the NixOS download page.
  3. Open UTM, Create a new Linux VM, Use Apple Virutalization & Enable Rosetta
  4. Select your nixos-minimal-...-aarch64-linux.iso
  5. Hardware:
  • CPU: 8 cores
  • RAM: 22528 MB
  1. configure login
  • sudo su
  • passwd (set to root)
  1. get machine ip: ip -brief address

NixOS VM using Parallels Desktop

  1. Install Parallels Desktop.
  2. Download a minimal 64-bit ARM ISO from the NixOS download page.
  3. In parallels: click "Install Windows or another OS from a DVD or image file"
  4. Select your nixos-minimal-...-aarch64-linux.iso
  5. Select "Other Linux"
  6. In Name, type "NixOS"
  7. Click "Customize settings before installation"
  8. Go to "Hardware"
  • CPU & Memory:
    • Processors: N - 2 cores where N is your core count (I have 10, so I pick 8)
    • Memory N - 8 GB where N is your GB count (I have 32, so I pick 24)
  • Graphics:
    • Resolution: More Space
    • Advanced > Ensure "Enable 3D acceleration" is enabled.
  • Mouse & Keyboard:
    • Click "Open Shortcuts Preferences" and uncheck all shortcuts.
    • Click "macOS System Shortcuts" in the sidebar, and change "Send macOS system shortcuts" to "always"
  • Shared Printers: uncheck "share mac printers with other linux"
  • Network: Source: Shared Network (Should be selected by default)
  • Hard Disk: Click Advanced > Properties. Select Size 256 GB. (More if you can, but I currently have just 1TB of storage)
  1. Boot the VM, you may have to re-attach the ISO by clicking the CD icon and rebooting.
  2. In the VM, type sudo su, then passwd, and type root twice.
  3. In the VM, type ip -brief address in order to see your VM's IP.
  4. On your Mac in this repository, type export NIXADDR=10.211.55.3 (replace the IP with the IP you found in step 11).
  5. On your Mac, in the same shell, type make vm/bootstrap0 When prompted for the root password, type root
  6. Your VM will reboot automtaically by this
  7. On your Mac, in the same shell, type make vm/bootstrap. (note that there's no 0 at the end this time)
  8. On your Mac, in the same shell, type make vm/secrets.
  9. Reboot your VM by typing reboot.
  10. Log into your VM
  11. In ~, run git clone git@github.com:cor/nixos-config
  12. Enter your SSH password (stored in 1Password)
  13. Run cd nixos-config && make switch
  14. reboot
  15. Open chromium, go to chrome://settings/cookies, and disable "Clear cookies and site data when you close all windows"
  16. Go to chrome://settings/search and set search engine to "DuckDuckGo"

You now have your VM fully set up! To make changes to the config, just edit the contenst ~/nixos-config, and run make switch

Raspberry Pi setup

To bootstrap the SD card:

  1. Enter orbstack
  2. nix build '.#nixosConfigurations.raspberry-pi.config.system.build.sdImage'
  3. cp ./result/sd-image/nixos-...-linux.img.zst /Users/cor/Desktop
  4. On macOS, download rpi-imager
  5. Insert SD card into MacBook
  6. Flash the .img.zst from your Desktop to the rPi's sd card.
  7. Insert sd card into raspberry pi and click the power button

Your Raspberry Pi should now be bootstrapped and you should be able to SSH into it.

To udpate the pi from the pi itself

  1. clone this repo on the pi
  2. sudo nixos-rebuild switch --flake .#raspberry-pi

Config is partially based on https://github.com/mitchellh/nixos-config