Nix packaging

From nix-community/nur-combined · View interactive version

Nix packaging is an AI agent skill from the GitHub repository nix-community/nur-combined. Use this when writing or modifying Nix package definitions and related repo exports in this NUR repository.

How to use this skill

Skill file

Use this when

Repository-specific ground rules

Packaging styles actually used in this repo

Python applications and packages

Used heavily for GUI apps and helpers.

Examples:

Common patterns:

Flutter applications

Example: pkgs/LoveIwara/default.nix

Use the pinned Flutter SDK's buildFlutterApplication (currently flutter347) for reproducible Linux desktop builds:

Rust packages

Example: pkgs/waybar-vd/default.nix

rustPlatform.buildRustPackage rec {
  pname = "...";
  version = "...";

  cargoLock.lockFile = ./Cargo.lock;
  postPatch = ''
    ln -s ${./Cargo.lock} Cargo.lock
  '';
}

Go packages

Example: pkgs/mihomo-smart.nix

buildGoModule rec {
  pname = "...";
  version = "...";
  vendorHash = "sha256-...";
}

npm dependencies

No exported package currently uses buildNpmPackage directly. npm usage here is limited to

offline dependency rebuilds inside other derivations:

Example: pkgs/wechat-web-devtools-linux

plus lockfiles; the derivation runs npm ci --offline --ignore-scripts with a FOD cache

to rebuild native npm modules (nodegit, node-pty, ...) with Electron headers.

bun + `stdenvNoCC` packages

Example: pkgs/mcp-cli.nix

This repo also contains packages that:

Gradle / JVM packages

Example: pkgs/jadx-headless-mcp/default.nix

stdenv.mkDerivation (finalAttrs: {
  nativeBuildInputs = [ gradle_9 jdk17 makeBinaryWrapper ];
  mitmCache = gradle_9.fetchDeps {
    pkg = finalAttrs.finalPackage; # required outside nixpkgs
    data = ./deps.json;
  };
  gradleBuildTask = "installDist";
})

with <attr>.mitmCache.updateScript on every bump.

nixpkgs default gradle may be too old for modern plugin versions.

-Dorg.gradle.java.installations.paths=${jdk17.home} — the build runs --offline.

Generic derivations

Examples:

Use stdenv.mkDerivation or stdenvNoCC.mkDerivation for asset packages, extracted binaries, or custom build workflows.

Export wiring patterns

Package export in `default.nix`

some-package = pkgs.callPackage ./pkgs/some-package.nix { };

Library export in `lib/default.nix`

{ pkgs }:
{
  someHelper = pkgs.callPackage ./someHelper/default.nix { };
}

Current repo-specific examples worth imitating

Hash techniques

Build once with a fake hash

hash = lib.fakeHash;

Then rebuild and copy the real hash from the failure output.

Prefetch helpers

nix-prefetch-url --unpack <url>
nix-prefetch-github owner repo --rev v1.0.0

Checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.