macOS/Linux - Nix ConfigΒΆ

For full documentation, visit hugohakem.github.io/nix-os.config.


My Nix config is heavily inspired by:

MotivationΒΆ

I chose Nix as my package manager because it enables:

  • Declarative Configuration: You can specify your configuration like a recipe, and Nix will seamlessly recreate it on any intended system. Sharing configs and environments becomes effortless!

  • Reproducibility: If it works on my machines, it will work on yours! With its inherent .lock file, package versioning is guaranteed to be consistent.

  • Reliability: Even if your build fails, previously installed packages remain intact, and you can easily roll back to previous build versions.

Note that NixOS is an operating system built on these concepts. It’s even more configurable, with hardware specifications, etc. I haven’t chosen this option yet as it is more advanced and less beginner-friendly. However, it’s possible to install NixOS on GCP (see Resources), and I may explore that in the future if a use case arises.

This Nix config relies on Nix Home Manager. I highly recommend checking the home-manager tutorial below in the resources section if you want to get familiar with the Nix syntax and how to obtain a minimal configuration.

Project LayoutΒΆ

.
β”œβ”€β”€ apps                    # Custom nix commands written in shell script
β”‚Β Β  β”œβ”€β”€ ...
β”‚Β Β  └── README.md
β”œβ”€β”€ flake.lock              
β”œβ”€β”€ flake.nix               # Core config
β”œβ”€β”€ gcp-installation.md
β”œβ”€β”€ hosts                   # Where `modules` are imported
β”‚Β Β  β”œβ”€β”€ darwin
β”‚Β Β  β”‚   └── ...
β”‚Β Β  β”œβ”€β”€ linux
β”‚Β Β  β”‚   └── ...
β”‚Β Β  └── README.md
β”œβ”€β”€ modules                 # Where files, packages, and programs are defined
β”‚Β Β  β”œβ”€β”€ darwin
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ ...
β”‚Β Β  β”‚Β Β  └── README.md
β”‚Β Β  β”œβ”€β”€ linux
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ ...
β”‚Β Β  β”‚Β Β  └── README.md
β”‚Β Β  └── shared
β”‚Β Β      β”œβ”€β”€ config          # Program configs like vscode, zsh, emacs
β”‚Β Β      β”‚Β Β  └── ...
β”‚Β Β   Β Β  β”œβ”€β”€ ...
β”‚Β Β      └── README.md
β”œβ”€β”€ overlays                # Package fixes
β”‚Β Β  β”œβ”€β”€ ...
β”‚Β Β  └── README.md
└── templates               # Project templates
    β”œβ”€β”€ deprecated          # Archived / for learning purposes
    β”‚Β Β  └── ...
    β”œβ”€β”€ pythonml
    β”‚Β Β  └── ...
    └── README.md

Getting StartedΒΆ

To set up a new machine, please follow the corresponding guide:

These guides will refer you to the various README.md files outlined in the Project Layout. You will find useful explanations to help you understand the code and get familiar with Nix as a package manager. Useful commands and typical workflows are also documented there.

To set up a new project with templates/pythonml, add it to your project directory by running the following commands in your $HOME directory:

mkdir projects
cp -r nixos-config/templates/pythonml projects/[name-of-the-project]

For further details, refer to templates/.

Note on My EditorΒΆ

As of today, my editor of choice is Visual Studio Code. However, you may find some Emacs-related code in modules/shared/config/emacs/. As I have paused my Emacs journey for now, any Emacs code has been commented out. See the note on my editor in modules/shared/config/README.md to learn how to change the Visual Studio Code configuration to suit your needs.

To-DoΒΆ

  • [ ] Test config on a blank GCP virtual machine

    • [ ] Eventually add guidelines on how to minimally set up a virtual machine

  • [ ] Test config on a new Mac and add installation guide

    • [ ] Complete [mac-installation.md]

  • [ ] Learn Emacs or Vim and provide my custom config as a safeguard for systems where VSCode remote-ssh is not possible

  • [ ] Provide custom configs for WezTerm and Zsh

Resources to Keep in MindΒΆ

Nix Official ResourcesΒΆ

ManualsΒΆ

GitHub ReposΒΆ

TutorialsΒΆ

AcknowledgementsΒΆ

As mentioned above, this configuration relies heavily on the NixOS/macOS backbone provided by dustinlyons, as well as afermg: Moby Config and leoank: Neusis Config.

I am particularly grateful to AlΓ‘n for introducing me to Nix and for his mentorship throughout my learning. I also thank Ank for the insightful discussions that helped refine my understanding of Nix.

As I am still learning about Nix, if you notice anything missing, bugs, or features that should be added, feel free to open an issue.