C.W.K.
Stream
Lesson 03 of 05 · published

The Five Commands That Cover 90% of Use

~14 min · nix, commands, flakes

Level 0Newbie
0 XP0/55 lessons0/16 achievements
0/80 XP to next level80 XP to go0% complete

Modern Nix has dozens of commands, but five carry most of the daily work for a non-expert. Learn these and you can be productive while you climb the rest of the curve.

nix shell nixpkgs#<pkg> drops you into a temporary subshell with the package available. Exit the shell, the package vanishes — your system stays untouched. This is the perfect 'try a tool without committing' workflow.

nix run nixpkgs#<pkg> -- <args> downloads and runs a package in one shot, like npx for the entire universe of packages.

nix develop enters the dev environment defined by your project's flake.nix. This is the production use of Nix — drop a flake.nix in your repo, and any teammate can run nix develop to get exactly your tool versions, regardless of their OS or what's already on their PATH.

nix search nixpkgs <query> finds packages by name or description. (You can also browse https://search.nixos.org/packages, which is faster.)

nix-env is the older, imperative interface — it permanently installs into your user profile. The flake-based commands (shell/run/develop) are the modern way; nix-env is mostly for legacy guides. Know it exists; prefer flakes.

Code

The five commands you actually need·bash
# Temporary shell — package vanishes on exit
nix shell nixpkgs#ripgrep nixpkgs#bat

# Run a one-shot, no install
nix run nixpkgs#cowsay -- "hello, Nix!"

# Enter the project's defined dev environment (uses ./flake.nix)
nix develop

# Search
nix search nixpkgs ripgrep

# Older, imperative install (mostly for legacy)
nix-env -iA nixpkgs.ripgrep
nix-env --rollback        # undo the last install
A minimal flake.nix for a project·nix
# flake.nix in your repo's root
{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  outputs = { self, nixpkgs }: {
    devShells.aarch64-darwin.default =
      let pkgs = import nixpkgs { system = "aarch64-darwin"; };
      in pkgs.mkShell {
        packages = with pkgs; [ nodejs_22 python313 postgresql_16 ripgrep ];
      };
  };
}

# Then any teammate runs:
#   nix develop
# ...and gets the exact same tool set, every time.

External links

Exercise

Try the temporary-shell trick on a real tool: 'nix shell nixpkgs#httpie nixpkgs#jq', then run 'http https://api.github.com | jq .current_user_url'. Exit the shell — both tools vanish. This 'try without committing' loop is the Nix workflow that hooks people.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.