This guide walks you through installing Nix, enabling flakes, and setting up a reproducible development environment on Arch Linux.
The recommended way to install Nix is via the official script:
sh <(curl -L https://nixos.org/nix/install) --daemonAfter installation, reload your shell:
source /etc/profileVerify the installation:
nix --versionSince flakes are an experimental feature, they must be explicitly enabled.
Run the following command:
mkdir -p ~/.config/nix
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.confThen restart your shell:
source /etc/profileCheck if flakes are enabled:
nix flake --helpIf you see a help message, flakes are enabled! β
1οΈβ£ Create a new project directory and initialize Git:
mkdir nix-project && cd nix-project
git init2οΈβ£ Create a flake.nix file:
nano flake.nixPaste the following minimal flake setup:
{
description = "A minimal Nix flake setup";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let
system = "x86_64-linux"; # Define the architecture
pkgs = nixpkgs.legacyPackages.${system}; # Correctly access package set
in {
devShells.${system}.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
curl
unzip
gcc
lcms2
wget
];
shellHook = ''
echo "Welcome to your Nix flake development shell!"
'';
};
};
}1οΈβ£ Ensure Git is clean (flakes require a Git repository):
git add .
git commit -m "Initial commit"2οΈβ£ Update the flake:
nix flake update3οΈβ£ Enter the flake development environment:
nix developTo exit the Nix development shell, simply run:
exitor press Ctrl + D.
You now have a fully reproducible Nix development environment using flakes! π
If you need to update dependencies later, run:
nix flake updateTo clean up unused packages:
nix-collect-garbage -d| Task | Command |
|---|---|
| Install Nix | sh <(curl -L https://nixos.org/nix/install) --daemon |
| Enable flakes | echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf |
| Create a new project | mkdir nix-project && cd nix-project |
| Initialize Git | git init && git add . && git commit -m "Initial commit" |
| Run a flake shell | nix develop |
| Exit the shell | exit or Ctrl + D |
| Update flakes | nix flake update |
| Clean up unused dependencies | nix-collect-garbage -d |