Nix 101 Course / Section 6: Composing nixpkgs: callPackage, override, project layout
Premium

6.6 Nix anti-patterns that bite you later

Lesson 45 of 68 · 15:43

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

About this lesson

None of these Nix anti-patterns look wrong when you write them. They bite months later, in 500 line files, when nobody can tell where a variable comes from or why an overlay is silently ignored. This lesson collects the patterns we have seen cause pain in many organizations: overused with, rec, accidental nixpkgs re-imports, wiped build phases, and misused callPackage.

In this video

  • Why with pkgs; at the top of a file hurts every future reader, and the inherit style that replaces it
  • The rec keyword: easy to write, expensive to read, and what to do instead
  • Reusing version inside a derivation, and the subtle way overrides then stop working as expected
  • nixpkgs amnesia: the forgotten function parameter that quietly throws away your overlays, config and pin
  • Overriding a whole build phase and deleting hooks other people rely on, plus the callPackage misuse that stacks overrides on overrides (and the function that exists for exactly that case)

After this lesson

You can spot these patterns in code review before they land, and explain to a colleague why the fix matters, not just that it does.

Builds on: override vs overrideAttrs (6.4)