Skip to content

Instantly share code, notes, and snippets.

@oliverdaff
Created March 12, 2025 20:29
Show Gist options
  • Save oliverdaff/5f3336a590a12241d290f970f705ce54 to your computer and use it in GitHub Desktop.
Save oliverdaff/5f3336a590a12241d290f970f705ce54 to your computer and use it in GitHub Desktop.

πŸš€ Getting Started with Nix and Flakes on Arch Linux

This guide walks you through installing Nix, enabling flakes, and setting up a reproducible development environment on Arch Linux.


πŸ”Ή Step 1: Install Nix 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

πŸ”Ή Step 2: Enable Flakes

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! βœ…


πŸ”Ή Step 3: Initialize a Flake Project

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!"
      '';
    };
  };
}

πŸ”Ή Step 4: Run Your 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

πŸ”Ή Step 5: Exit the Nix Shell

To exit the Nix development shell, simply run:

exit

or press Ctrl + D.


πŸŽ‰ Done!

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

βœ… Summary of Commands

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment