Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

General purpose Nix starter template for macOS or NixOS w/ step-by-step instructions

License

NotificationsYou must be signed in to change notification settings

dustinlyons/nixos-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Starter TemplateStatix Lint

Overview

Hey, you made it! Welcome. 🤓

Nix is a powerful package manager for Linux and Unix systems that ensures reproducible, declarative, and reliable software management.

This repository contains configuration for a general-purpose development environment that runs Nix on macOS, NixOS, or both simultaneously.

I use it daily on my 🧑🏻‍💻 Macbook Pro and an x86 PC in my home office. It also runs as a VM on your Mac. Many others have reported that it's working for them too.

Check out the step-by-step commands below to get started!

Table of Contents

Features

  • Nix Flakes: No confusingconfiguration.nix entry point,no Nix channels─ justflake.nix
  • Same Environment Everywhere: Easily share config across Linux and macOS (both Nix and Home Manager)
  • macOS Dream Setup: Fully declarative macOS (Apple / Intel) w/ UI, dock and macOS App Store apps
  • Simple Bootstrap: Simple Nix commands to start from zero, both x86 and macOS platforms
  • Managed Homebrew: Zero maintenance homebrew environment withnix-darwin andnix-homebrew
  • Disk Management: Declarative disk management withdisko, say goodbye to disk utils
  • Secrets Management: Declarative secrets withagenix for SSH, PGP, syncthing, and other tools
  • Super Fast Emacs: Bleeding edge Emacs that fixes itself, thanks to acommunity 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: managed 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
  • Backed by Continuous Integration: Flake auto updates weekly if changes don't break starter build

Testimonials

Screenshot 2024-10-31 at 9 32 38 AM

Screenshot 2024-10-31 at 11 07 07 AM

Screenshot 2024-10-31 at 9 33 27 AM

Screenshot 2024-10-31 at 11 00 11 AM

Screenshot 2025-01-28 at 1 56 59 PM

Videos

macOS

Updating dependencies with one command

Build.mov

Instant Emacs 30 thanks to daemon mode

  • GUI
Emacs.mov
  • Terminal
Emacs_Terminal.mov

NixOS

NixOS.mp4

Disclaimer

Installing Nix on macOS will create an entirely separate volume. It may exceed many gigabytes in size.

Some folks don't like this. If this is you, turn back now!

Note

Don't worry, you can alwaysuninstall Nix later.

Layout

.├── apps         # Nix commands used to bootstrap and build configuration├── hosts        # Host-specific configuration├── modules      # macOS and nix-darwin, NixOS, and shared configuration├── overlays     # Drop an overlay file in this dir, and it runs. So far, mainly patches.├── templates    # Starter versions of this configuration

Installing

For macOS (October 2025)

This configuration supports both Intel and Apple Silicon Macs.

1. Install dependencies

xcode-select --install

2. Install Nix

Thank you for theinstaller,Determinate Systems!

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

After installation, open a new terminal session to make thenix executable available in your$PATH. You'll need this in the steps ahead.

Important

The installer will ask if you want to install Determinate Nix. AnswerNo as itcurrently conflicts withnix-darwin.

Important

If usingthe official installation instructions instead,flakes andnix-command aren't available by default.

You'll need to enable them.

Add this line to your/etc/nix/nix.conf file

experimental-features = nix-command flakes

OR

Specify experimental features when usingnix run below

nix --extra-experimental-features 'nix-command flakes' run .#<command>

Important

If you haven't upgraded to macOS Sequioa yet, read this article:Nix Support for macOS Sequioa.

3. Initialize a starter template

Choose one of two options

Simplified version without secrets management

  • Great for beginners, enables you to get started quickly and test out Nix.
  • Forgoing secrets just means you must configure apps that depend on keys, passwords, etc., yourself.
  • You can always add secrets later.
mkdir -p nixos-config&&cd nixos-config&& nix flake --extra-experimental-features'nix-command flakes' init -t github:dustinlyons/nixos-config#starter

Full version with secrets management

  • Choose this to add more moving parts for a 100% declarative configuration.
  • This template offers you a place to keep passwords, private keys, etc.as part of your configuration.
mkdir -p nixos-config&&cd nixos-config&& nix flake --extra-experimental-features'nix-command flakes' init -t github:dustinlyons/nixos-config#starter-with-secrets

4. Makeapps executable

find apps/$(uname -m| sed's/arm64/aarch64/')-darwin -type f\( -name apply -o -name build -o -name build-switch -o -name create-keys -o -name copy-keys -o -name check-keys -o -name rollback\) -exec chmod +x {}\;

5. Apply your current user info

Run this Nix command to replace stub values with your system properties, username, full name, and email.

Your email is only used in thegit configuration.

nix run .#apply

Note

If you're using a git repository, only files in the working tree will be copied to theNix Store.

You must rungit add . first.

6. Decide what packages to install

You can search for packages on theofficial NixOS website.

Review these files

7. Review your shell configuration

Add anything from your existing~/.zshrc, or just review the new configuration.

Review these files

8. Optional: Setup secrets

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

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

In Github, create a privatenix-secrets repository with at least one file (like aREADME). You'll enter this name during installation.

8b. Install keys

Before generating your first build, these keys must exist in your~/.ssh directory. Don't worry, I provide a few commands to help you.

Key NamePlatformDescription
id_ed25519macOS / NixOSGithub key with access tonix-secrets. Not copied to host, used only during bootstrap.
id_ed25519_agenixmacOS / NixOSPrimary key for encrypting and decrypting secrets. Copied over to host asid_ed25519.

Run one of these commands:

Copy keys from USB drive

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

Keys must be namedid_ed25519 andid_ed25519_agenix.

nix run .#copy-keys
Create new keys
nix run .#create-keys

Note

If you choose this option, make sure tosave the value ofid_ed25519.pub to Github.

cat /Users/$USER/.ssh/id_ed25519.pub| pbcopy# Copy key to clipboard
Check existing keys

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

nix run .#check-keys

9. Install configuration

Ensure the build works before deploying the configuration, run:

nix run .#build

Note

If you're using a git repository, only files in the working tree will be copied to theNix Store.

You must rungit add . first.

Warning

You may encountererror: Unexpected files in /etc, aborting activation ifnix-darwin detects it will overwritean existing/etc/ file. The error will list the files like this:

The following files have unrecognized content and would be overwritten:  /etc/nix/nix.conf  /etc/bashrcPlease check there is nothing critical in these files, rename them by adding .before-nix-darwin to the end, and then try again.

Backup and move the files out of the way and/or edit your Nix configuration before continuing.

Warning

You may encountererror: Build user group has mismatching GID, aborting activation if you have already upgraded to Sequoia but had notprepared Nix before that.The error will list the files like this:

error: Build user group has mismatching GID, aborting activationThe default Nix build user group ID was changed from 30000 to 350.You are currently managing Nix build users with nix-darwin, but yournixbld group has GID 350, whereas we expected 30000.

You will have touninstall Nix, andinstall Nix again with--nix-build-group-id 30000 flag. See more here:

10. Make changes

Finally, alter your system with this command:

nix run .#build-switch

Caution

~/.zshrc will be replaced with thezsh configuration from this repository. Make sure this is what you want.

For NixOS

This configuration supports bothx86_64 andaarch64 platforms.

1. Burn and use the latest ISO

Download and burnthe minimal ISO image to a USB, or create a new VM with the ISO as base. Boot the installer.

If you're building a VM on an Apple Silicon Mac, choose64-bit ARM.

Quick Links

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 privatenix-secrets repository with at least one file (like aREADME). You'll enter this name during installation.

2b. Install keys

Before generating your first build, these keys must exist in your~/.ssh directory. Don't worry, I provide a few commands to help you.

Key NamePlatformDescription
id_ed25519macOS / NixOSGithub key with access tonix-secrets. Not copied to host, used only during bootstrap.
id_ed25519_agenixmacOS / NixOSPrimary key for encrypting and decrypting secrets. Copied over to host asid_ed25519.

Run one of these commands:

Copy keys from USB drive

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

Keys must be namedid_ed25519 andid_ed25519_agenix.

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

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

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

3. Install configuration

Pick your template

Important

For Nvidia cards, select the second option,nomodeset, when booting the installer, or you will see a blank screen.

Caution

Running this will reformat your drive to theext4 filesystem.

Simple

  • Great for beginners, enables you to get started quickly and test out Nix.
  • Forgoing secrets means you must configure apps that depend on keys or passwords yourself.
  • You can always add secrets later.
sudo nix run --extra-experimental-features'nix-command flakes' github:dustinlyons/nixos-config#install

With secrets

  • Choose this to add more moving parts for a 100% declarative configuration.
  • This template offers you a place to keep passwords, private keys, etc.as part of your configuration.
sudo nix run --extra-experimental-features'nix-command flakes' github:dustinlyons/nixos-config#install-with-secrets

4. Set user password

On first boot at the login screen:

  • Use shortcutCtrl-Alt-F2 (orFn-Ctrl-Option-F2 if on a Mac) to move to a terminal session
  • Login asroot using the password created during installation
  • Set the user password withpasswd <user>
  • Go back to the login screen:Ctrl-Alt-F7
  • Review the essential hotkeys inNixOS README to get started with the bspwm window manager

How to create secrets

To create a new secretsecret.age, firstcreate asecrets.nix file at the root of yournix-secrets repository. Use this code:

Note

secrets.nix is interpreted by the imperativeagenix commands to pick the "right" keys for your secrets.

Think of this file as the config file foragenix. It's not part of your system configuration.

secrets.nix

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

Values foruser1 should be your public key, or if you prefer to have keys attached to hosts, use thesystem1 declaration.

Now that we've configuredagenix with oursecrets.nix, it's time to create our first secret.

Run the command below.

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

This opens an editor to accept, encrypt, and write your secret to disk.

The command will look up the public key forsecret.age, defined in yoursecrets.nix, and check for its private key in~/.ssh/.

To override the SSH path, provide the-i flag with a path to yourid_ed25519 key.

Write your secret in the editor, save, and commit the file to yournix-secrets repo.

Now we have two files:secrets.nix and oursecret.age.

Here's a more step-by-step example:

Secrets Example

Let's say I wanted to create a new secret to hold my Github SSH key.

I wouldcd into mynix-secrets repo directory, verify theagenix configuration (namedsecrets.nix) exists, then run

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

This would start avim session.

I would enter insert mode:i, copy+paste the key, hit Esc and then type:w to save it, resulting in the creation of a new file,github-ssh-key.age.

Then, I would editsecrets.nix to include a line specifying the public key to use for my new secret. I specify a user key, but I could just as easily specify a host key.

secrets.nix

letdustin="ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIL0idNvgGiucWgup/mP78zyC23uFjYq0evcWdjGQUaBH";users=[dustin];systems=[];in{"github-ssh-key.age".publicKeys=[dustin];}

Finally, I'd commit all changes to thenix-secrets repository, go back to mynixos-config and runnix flake update to update the lock file.

The secret is now ready to use. Here's anexample from my configuration. In the end, this creates a symlink to a decrypted file in the Nix Store that reflects my original file.

Making changes

With Nix, changes to your system are made by

This is all wrapped up in thebuild-switch run command.

Development workflow

So, in general, the workflow for managing your environment will look like

  • make changes to the configuration
  • runnix run .#build-switch
  • watch Nix,nix-darwin,home-manager, etc do their thing
  • go about your way and benefit from a declarative environment

Trying packages

For quickly trying a package without installing it, I usually run

nix shell nixpkgs#hello

wherehello is the package name fromnixpkgs.

Compatibility and Feedback

Platforms

This configuration has been tested and confirmed to work on the following platforms:

  • Newer M1/M2/M3 Apple Silicon Macs
  • Older x86_64 (Intel) Macs
  • Bare metal x86_64 PCs
  • NixOS VMs inside VMWare on macOS
  • macOS Sonoma VMs inside Parallels on macOS

Feedback and Questions

Have feedback or questions? Feel free to use thediscussion forum.

Contributing

Interested in contributing to this project? Here's how you can help:

  • Code Contributions: If you're interested in contributing code, please start by looking at open issues or feature requests. Fork the repository, make your changes, and submit a pull request. Make sure your code adheres to the existing style. For significant changes, consider opening an issue for discussion before starting work.

  • Reporting Bugs: If you encounter bugs or issues, please help by reporting them. Open a GitHub Issue and include as much detail as possible: what you were doing when the bug occurred, steps to reproduce the issue, and any relevant logs or error messages.

Appendix

Why Nix Flakes

Reasons to jump into flakes and skipnix-env, Nix channels, etc

  • Flakes work just like other package managers you already know:npm,cargo,poetry,composer, etc. Channels work more like traditional Linux distributions (like Ubuntu), which most devs don't know.
  • Flakes encapsulate not just project dependencies, but Nix expressions, Nix apps, and other configurations in a single file. It's all there in a single file. This is nice.
  • Channels lock all packages to one big globalnixpkgs version. Flakes lock each individual package to a version, which is more precise and makes it much easier to manage overall.
  • Flakes have a growing ecosystem (seeFlake Hub orDev Env), so you're future-proofing yourself.

NixOS Components

ComponentDescription
Window ManagerXorg + bspwm
Terminal Emulatoralacritty
Barpolybar
Application Launcherrofi
Notification Daemondunst
Display Managerlightdm
File Managerthunar
Text Editoremacs daemon mode
Media Playercider
Image Viewerfeh
Screenshot Softwareflameshot

License

This project is released under theBSD-3-Clause license.

Support

Did you find my project useful? Your support is appreciated.

Buy Me A Coffee

Stars

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

Star History Chart

About

General purpose Nix starter template for macOS or NixOS w/ step-by-step instructions

Topics

Resources

License

Stars

Watchers

Forks

Contributors15


[8]ページ先頭

©2009-2025 Movatter.jp