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) --daemon
After installation, reload your shell:
source /etc/profile
Verify the installation:
nix --version
Since 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.conf
Then restart your shell:
source /etc/profile
Check if flakes are enabled:
nix flake --help
If you see a help message, flakes are enabled! β
1οΈβ£ Create a new project directory and initialize Git:
mkdir nix-project && cd nix-project
git init
2οΈβ£ Create a flake.nix
file:
nano flake.nix
Paste 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 update
3οΈβ£ Enter the flake development environment:
nix develop
To exit the Nix development shell, simply run:
exit
or press Ctrl + D
.
You now have a fully reproducible Nix development environment using flakes! π
If you need to update dependencies later, run:
nix flake update
To 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 |