Skip to content

Instantly share code, notes, and snippets.

@Pamplemousse
Last active April 22, 2025 13:56
Show Gist options
  • Save Pamplemousse/935748883c246e5c2eb6416b4f2beb51 to your computer and use it in GitHub Desktop.
Save Pamplemousse/935748883c246e5c2eb6416b4f2beb51 to your computer and use it in GitHub Desktop.

Contribute to nixpkgs cheatsheet

Tips and tricks for one who wants to write expressions to contribute to NixOS/nixpkgs .

Build a package from local nixpkgs

nix-build <PATH_TO_NIXPKGS> -A <PACKAGE>

Override the value of a parameter given to a package

# to build
nix-build -E "with import <nixpkgs>{}; <PACKAGE>.override { <PARAMETER> = <VALUE>; }"
# for a shell
nix-shell -p "with import <nixpkgs> {}; pkgs.<PACKAGE>.override{ <PARAMETER> = <VALUE>; }"

Generate a patch to be used during the patchPhase

git diff > nixpkgs/pkgs/the/package/0001-changes.patch

Use local repository for NUR

{
  packageOverrides = pkgs: {
    nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") {
      inherit pkgs;
      repoOverrides = {
        angr = import /home/pamplemousse/Workspace/angr/nixpkgs {};
      };
    };
  };
}

Pull a PR to test locally

git fetch nixos pull/<PR #>/head

List packages that a given user is a maintainer of (defaults to me)

cat << __EOF__ > mypkgs.nix && nix-build mypkgs.nix 2>/dev/null
{ pkgs ? import ./. {}
, maintainer ? "pamplemousse"
}:

with pkgs.lib;
filterAttrs (name: value:
 (builtins.tryEval value).success &&
 elem maintainers.\${maintainer} (value.meta.maintainers or [])
) pkgs
__EOF__

Replace a module with a local one

({ modulesPath, ...}: {
  disabledModules = [
    (modulesPath + "<path to the module in nixpkgs>.nix")
  ];

  imports = [
    <path to your module>.nix
  ];
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment