These are my complete configurations for use in my daily life using macOS alongside Nix, which is more than my main package manager, being the most powerful tool alongside home-manager and nix-darwin.
Maybe this is the time to try something new. If you want, start by running sh <(curl -L https://nixos.org/nix/install) --daemon
in your terminal.
Once you have Nix properly installed on your machine, now is the time to clone this configuration to ~/.config/snowflake
and start having fun in the snow.
git clone https://github.com/lalit64/dotfiles.git ~/.config/nix-darwin
After cloning the repository we can build with nix-darwin
:
# This will activate flakes to start the installation and build. Note that my machine name is "lalits-mbp".
nix --extra-experimental-features "nix-command flakes" build .#darwinConfigurations.lalits-mbp.system
Then just run:
# nix-darwin will perform a complete rebuild of the system.
./result/sw/bin/darwin-rebuild switch --flake ~/.config/snowflake/.#lalits-mbp
Done. Now, my entire workflow is in your hands for use. With flakes I can guarantee that everything is in its specific version, validating inconsistencies and guaranteeing a perfect replica.
Now let's talk a little about the organizational structure here so we can analyze more carefully how everything works.
Take a look:
.
├── README.md
├── flake.lock
├── flake.nix
├── img
│ ├── darwin.png
│ └── nix.png
├── modules
│ ├── darwin
│ │ ├── default.nix
│ │ └── settings
│ │ ├── environment.nix
│ │ ├── homebrew.nix
│ │ ├── system.nix
│ │ └── services.nix***
│ └── home-manager
│ ├── default.nix
│ └── settings
│ ├── inputrc
│ ├── apps.nix***
│ └── zsh.nix
└── result -> /nix/store/somehash
The apps.nix***
and services.nix***
files are symbolic only and indicate specific application and service configurations only. While applications are managed by home-manager
, services are managed directly by nix-darwin
as they need permissions to bootstrap and control with launchctl
.
flake.nix
: Contains the base configuration of our flake, controlling the expected inputs and outputs, in addition to managing the external urls ofhome-manager
andnix-darwin
;modules/darwin/default.nix
: Contains the complete configuration of our nix-darwin, including imports for configurations, extra options, among others;modules/darwin/settings/environment.nix
: Contains the complete environment configuration, including system path, system packages and login shell (zsh
in this case);modules/darwin/settings/homebrew.nix
: Contains the homebrew configuration, including casks, brews and taps;modules/darwin/settings/system.nix
: Contains the entire system configuration, including appearance, dock management, I/O devices settings, and others;modules/home-manager/default.nix
: Contains thehome-manager
configuration imports, packages and session variables;modules/home-manager/settings/zsh.nix
: Contains the entire zsh configuration (similar to your.zshrc
with steroids);result
: A symlink which apoints to your build at/nix/store
.
Note: if you want to install a simple package, go to modules/home-manager/default.nix
and add the package name to the home.packages
list. But, if you want to strictly configure your package, then include a file in modules/home-manager/settings
with the name of your package and its settings following the template below:
# At modules/home-manager/settings/yourpackage.nix
{ pkgs, ... }: {
programs.yourpackage = {
# Your settings
};
}
And don't forget to import in modules/home-manager/default.nix
:
# ...
imports = [
./settings/zsh.nix
./settings/yourpackage.nix
];
# ...
Amazing! To search for packages you can use the official search at nixos.org.
To find more content about Nix, follow the links below:
- NixOS Wiki (Popular wiki to Nix and NixOS users)
- NixOS Official Website
- NixOS GitHub
- NixOS at Mastodon
- NixOS at Twitter
- NixOS at YouTube
Talks and presentations about Nix and NixOS:
- What Nix Can Do - Matthew Croughan
- A Gentle Introduction to Nix - Bryan Honof
- Getting Started with Nix - OpenTechLab
- Nix for Startups (full course) - @ecto
- Build A Portable Development Environment With Nix Package Manager - Jake Wiesler
- Nix flakes explained - Vimjoyer
Any problems with the workflow, documentation or code? Submit an issue.
Thanks to guto for giving me a template on how to do this