8000 GitHub - lokhmakov/dustinlyons-nixos-config: My personal Nix configuration for MacOS and NixOS w/ starter templates + step-by-step guides ✨
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

lokhmakov/dustinlyons-nixos-config

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nix for MacOS + NixOS

GitHub last commit

Overview

Hey, you made it! Welcome. 🤓

This Nix configuration runs on MacOS, NixOS, or both simultaneously. It's also a good example of a MacOS Nix flake.

I use this daily on my 🧑🏻‍💻 M1 Macbook Pro and an x86 PC in my home office.

Check out the starter templates below to get started!

Layout

.
├── bin          # Optional scripts used to run build/update
├── shared       # Shared configurations applicable to all systems
├── darwin       # MacOS and nix-darwin configuration
├── nixos        # My NixOS desktop-related configuration
├── overlays     # Drop an overlay file in this dir, and it runs. So far, mainly patches.
├── templates    # Starter versions of this configuration

Features

  • Nix Flakes: 100% flake driven, no configuration.nix, no Nix channels─ just flake.nix
  • Same Environment Everywhere: Easily share config across Linux and Mac (both Nix and Home Manager)
  • MacOS Dream Setup: Fully declarative MacOS, including UI, dock and MacOS App Store apps
  • Simple Bootstrap: Simple Nix commands to start from zero, both x86 and MacOS platforms
  • Managed Homebrew: Fully managed homebrew environment with nix-darwin and nix-homebrew
  • Disk Management: Declarative disk management with disko, say goodbye to disk utils
  • Secrets Management: Declarative secrets with agenix for SSH, PGP, syncthing, and other tools
  • Super Fast Emacs: Bleeding edge Emacs that fixes itself, thanks to a community overlay
  • Built In Home Manager: home-manager module for seamless configuration (no extra clunky CLI steps)
  • NixOS Environment: Extensively configured NixOS including clean aesthetic + window animations
  • Nix Overlays: Auto-loading of Nix overlays: drop a file in a dir and it runs (great for patches!)
  • Declarative Sync: No-fuss Syncthing: manage 10000 d keys, certs, and configuration across all platforms
  • Emacs Literate Configuration: Large Emacs literate configuration to explore (if that's your thing)
  • Simplicity and Readability: Optimized for simplicity and readability in all cases, not small files everywhere

Videos

MacOS

Updating dependencies with one command

Build.mov

Instant Emacs 29 thanks to daemon mode

GUI

Emacs.mov

Terminal

Emacs_Terminal.mov

NixOS

NixOS.mp4

Installing

For MacOS

I've tested these instructions on a fresh Macbook Pro as of September 2023.

1. Install dependencies

xcode-select --install

2. Install Nix

Thank you for the installer, Determinate Systems!

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install

3. Initialize a starter template

This is a simplified version without secrets management.

nix flake init -t github:dustinlyons/nixos-config#starter

This is a full version with secrets management.

nix flake init -t github:dustinlyons/nixos-config#starterWithSecrets

4. Apply your current user info

Run this script to replace stub values with your username, full name, and email.

chmod +x bin/apply && bin/apply

5. Decide what packages to install

You can search for packages on the official NixOS website.

Review these files

  • darwin/casks
  • darwin/packages
  • darwin/home-manager
  • nixos/packages
  • shared/packages

6. Optional: Setup secrets

If you are using the starter with secrets, there are a few additional steps.

6a. Create a private Github repo to hold your secrets

In Github, create a private nix-secrets repository.

Then, change the nix-secrets input in the flake.nix to reference it.

6b. Install keys

Before geneating your first build, these keys need to exist in your ~/.ssh directory. I've provided a few helper commands below. Choose one.

Key Name Platform Description
id_ed25519 MacOS / NixOS Used to download secrets from Github.
id_ed25519_agenix MacOS / NixOS Used to encrypt and decrypt secrets.
Copy keys from USB drive

This script auto-detects a USB drive connected to the current system.

Keys must be named id_ed25519 and id_ed25519_agenix.

nix run github:dustinlyons/nixos-config#copyKeys
Create new keys
nix run github:dustinlyons/nixos-config#createKeys
Check existing keys

If you're rolling your own, just check they are installed correctly.

nix run github:dustinlyons/nixos-config#checkKeys

7. Install configuration

First-time installations require you to move the current /etc/nix/nix.conf out of the way.

sudo mv /etc/nix/nix.conf /etc/nix/nix.conf.before-nix-darwin

Then, run this script, which wraps the Nix commands to build and deploy a new Nix generation.

chmod +x bin/darwin-build && chmod +x bin/build && bin/build

For NixOS

1. Burn the latest ISO

Download and burn the minimal ISO image. Boot the installer.

2. Optional: Setup secrets

If you are using the starter with secrets, there are a few additional steps.

2a. Create a private Github repo to hold your secrets

In Github, create a private nix-secrets repository.

Then, change the nix-secrets input in the flake.nix to reference it.

2b. Install keys

Before geneating your first build, these keys need to exist in your ~/.ssh directory. I've provided a few helper commands below. Choose one.

Key Name Platform Description
id_ed25519 MacOS / NixOS Used to download secrets from Github.
id_ed25519_agenix MacOS / NixOS Used to encrypt and decrypt secrets.
Copy keys from USB drive

This script auto-detects a USB drive connected to the current system.

Keys must be named id_ed25519 and id_ed25519_agenix.

nix run --extra-experimental-features 'nix-command flakes' github:dustinlyons/nixos-config#copyKeys
Create new keys
nix run --extra-experimental-features 'nix-command flakes' github:dustinlyons/nixos-config#createKeys
Check existing keys

If you're rolling your own, just check they are installed correctly.

nix run --extra-experimental-features 'nix-command flakes' github:dustinlyons/nixos-config#checkKeys

3. Install configuration

Run command

After the keys are in place, you're good to go. Run either of these commands:

Important

For Nvidia cards, select the second option, nomodeset, when booting the installer.

Warning

Running this will reformat your drive to the ext4 filesystem.

Simple

nix run --extra-experimental-features 'nix-command flakes' github:dustinlyons/nixos-config#install

With secrets

nix run --extra-experimental-features 'nix-command flakes' github:dustinlyons/nixos-config#installWithSecrets

4. Set user password

On first boot at the login screen:

  • Use the shortcut Ctrl-Alt-F2 to move to a terminal session
  • Login as root using the password created during installation
  • Set the user password with passwd <user>
  • Go back to the login screen: Ctrl-Alt-F7

How to create secrets

To create a new secret secret.age, first create a secrets.nix file at the root of your nix-secrets repository. This is only used by the agenix CLI command. It assumes your SSH private key is in ~/.ssh/ or you can provide the -i flag with a path to your id_ed25519 key.

let
  user1 = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL0idNvgGiucWgup/mP78zyC23uFjYq0evcWdjGQUaBH";
  users = [ user1 ];

  system1 = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPJDyIr/FSz1cJdcoW69R+NrWzwGK/+3gJpqD1t8L2zE";
  systems = [ system1 ];
in
{
  "secret.age".publicKeys = [ user1 system1 ];
}

Then run this command:

EDITOR=vim nix run github:ryantm/agenix -- -e secret.age

This opens an editor to accept, encrypt, and write your secret to disk. Commit the file to your nix-secrets repo and add a reference in the secrets.nix of your nixos-config.

Secrets used in my configuration

Secret Name Platform Description
syncthing-cert MacOS / NixOS Syncthing certificate
syncthing-key MacOS / NixOS Syncthing key
github-ssh-key MacOS / NixOS GitHub SSH key
github-signing-key MacOS / NixOS GitHub signing key

These are the secrets I use.

When changing secrets after your configuration exists, be sure to run nix flake update from your nixos-config so that you reference the latest change.

Live ISO

Not yet available. Coming soon.

nix run --extra-experimental-features 'nix-command flakes' github:dustinlyons/nixos-config#live

Making changes

With Nix, changes to your system are made by

For MacOS

nix build .#darwinConfigurations.macos.system && \
./result/sw/bin/darwin-rebuild switch --flake .#macos

Optional script to save keystrokes

bin/build

For NixOS

sudo nixos-rebuild switch --flake .#nixos

Optional script to save keystrokes

bin/build

Update dependencies

nix flake update

Appendix

NixOS Components

Component Description
Window Manager Xorg + bspwm
Terminal Emulator alacritty
Bar polybar
Application Launcher rofi
Notification Daemon dunst
Display Manager lightdm
File Manager thunar
Text Editor emacs daemon mode
Media Player cider
Image Viewer feh
Screenshot Software flameshot

Stars

"All we have to decide is what to do with the time that is given us." - J.R.R. Tolkien

Star History Chart

Follow @dustinhlyons

About

My personal Nix configuration for MacOS and NixOS w/ starter templates + step-by-step guides ✨

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Nix 63.8%
  • Shell 32.2%
  • Emacs Lisp 4.0%
0