Skip to main content

πŸ§™β€β™‚οΈ Intro to Nix & NixOS β€” A Developer's Guide

🧠 What is Nix?​

Nix is a powerful, declarative, and reproducible package manager that isolates dependencies and environments.

It’s like:

  • brew + docker + asdf + git β€” all rolled into one.
  • A package manager that lets you declare your entire dev environment as code.
  • A system that avoids "it works on my machine" bugs forever.

🐧 What is NixOS?​

NixOS is a Linux distro built entirely with Nix. Every part of the system β€” packages, services, even the kernel β€” is declarative and reproducible.

While NixOS is amazing, you do NOT need to use NixOS to use Nix. It works on macOS, Debian, Ubuntu, etc.


πŸš€ Quickstart​

1. Install Nix (single-user mode)​

curl -L https://nixos.org/nix/install | sh

Then restart your terminal or source the profile:

. ~/.nix-profile/etc/profile.d/nix.sh

πŸ“ On macOS with M1/M2: use nix-darwin or homebrew + Rosetta compat mode.


2. Clone the Project and Open a Dev Shell​

git clone https://github.com/your/repo.git
cd repo
nix develop

This drops you into a shell with all the tools you need: Node, Python, Neovim, etc.


🧩 Example: flake.nix​

Here’s a ready-to-use flake.nix file you can add to any project:

{
description = "A reproducible dev environment with Nix";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in {
devShells.default = pkgs.mkShell {
name = "dev-env";

buildInputs = [
pkgs.git
pkgs.nodejs
pkgs.python3
pkgs.neovim
pkgs.jq
pkgs.curl
pkgs.htop
pkgs.fzf
pkgs.ripgrep
pkgs.fd
pkgs.bat
pkgs.zsh
pkgs.gcc
pkgs.clang
pkgs.make
];

shellHook = ''
echo "πŸ§™ Welcome to your Nixified dev shell"
export PATH=$PATH:~/.npm-global/bin
'';
};
});
}

πŸ›  What Can You Use Nix For?​

Use CaseNix Advantage
Dev environment setupReproducible, fast onboarding
CI pipelinesClean, cacheable, deterministic
Multi-version language supportIsolated, conflict-free
Dotfile & tooling bootstrapsDeclarative, shareable
Container image buildingNix β†’ Docker or OCI image support
System config (via NixOS)Full-system version control

πŸ§™β€β™‚οΈ Real-World Dev Flow​

nix develop     # Drops you into your dev shell
nix flake check # Validates flake setup
nix build # Build project artifacts with reproducibility

πŸ“¦ P6M Nix Channels​

The P6M platform provides pre-built Nix channels for easy access to our tools and packages:

Archetect Channel​

# Add the Archetect channel
nix-channel --add https://developer.p6m.dev/channels/archetect/ archetect
nix-channel --update

# Install Archetect
nix-env -iA archetect.archetect

P6M Platform Tools​

# Add the P6M channel
nix-channel --add https://developer.p6m.dev/channels/p6m/ p6m
nix-channel --update

# Install P6M CLI tools
nix-env -iA p6m.p6m-cli

Using in Flakes​

{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
p6m.url = "https://developer.p6m.dev/channels/p6m/nixexprs.tar.xz";
archetect.url = "https://developer.p6m.dev/channels/archetect/nixexprs.tar.xz";
};

outputs = { nixpkgs, p6m, archetect, ... }: {
devShells.default = nixpkgs.legacyPackages.x86_64-linux.mkShell {
buildInputs = [
p6m.packages.x86_64-linux.p6m-cli
archetect.packages.x86_64-linux.archetect
];
};
};
}

🧠 Pro Tips​

  • Use direnv with use flake for auto-loading shells
  • Use lorri for auto dev-env reloads
  • Use nix fmt to format flake.nix

πŸ’¬ Resources​


πŸ§ͺ "Nix doesn’t install tools. It summons them."
β€” Everyone who’s used it more than twice