Nixpkgs/Patching Nixpkgs: Difference between revisions

m Fix indenting in code example
Ibizaman (talk | contribs)
Add more versatile way of using applyPatches.
 
(2 intermediate revisions by 2 users not shown)
Line 16: Line 16:
<syntaxHighlight lang=nix>
<syntaxHighlight lang=nix>
inputs = {
inputs = {
    # ...
  # ...
    nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
  nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
    # ...
  # ...
};
};
</syntaxHighlight>
</syntaxHighlight>
Line 28: Line 28:
redirect to https://patch-diff.githubusercontent.com/raw/NixOS/nixpkgs/pull/344917.patch. We can use the latter.
redirect to https://patch-diff.githubusercontent.com/raw/NixOS/nixpkgs/pull/344917.patch. We can use the latter.


<syntaxHighlight lang=nix>
<syntaxhighlight lang="nix">
    let
let
        pkgs-unstable' =
  nixpkgs-unstable' =
        (import nixpkgs-unstable {
    ((import nixpkgs-unstable {
            system = "x86_64-linux";
      system = "x86_64-linux";
        }).applyPatches
    }).applyPatches
            {
      {
                name = "nixpkgs-unstable-patched";
        name = "nixpkgs-unstable-patched";
                src = inputs.nixpkgs-unstable;
        src = inputs.nixpkgs-unstable;
                patches = [
        patches = [
                    (builtins.fetchurl {
          (builtins.fetchurl {
                    url = "https://patch-diff.githubusercontent.com/raw/NixOS/nixpkgs/pull/344917.patch";
            url = "https://patch-diff.githubusercontent.com/raw/NixOS/nixpkgs/pull/344917.patch";
                    sha256 = "sha256-aws9J5ZNUyz4Z2RqPVEovBTNng4AdhzS03Bqg8jejWQ=";
            sha256 = "sha256-aws9J5ZNUyz4Z2RqPVEovBTNng4AdhzS03Bqg8jejWQ=";
                    })
          })
                ];
        ];
            };
      }).src;
        pkgs-unstable = import pkgs-unstable' {
  patched-lib = nixpkgs-unstable'.lib;
            system = "x86_64-linux";
  pkgs-unstable = import nixpkgs-unstable' {
        };
    system = "x86_64-linux";
    # ...
  };
</syntaxHighlight>
# ...
</syntaxhighlight>


In the above example we create a derivation with the patch applied, called <code>pkgs-unstable'</code>. We then import that new
In the above example we create a derivation with the patch applied, called <code>nixpkgs-unstable'</code>. Pay attention we take the <code>src</code> attribute to get back the top-level nixpkgs. We can then access <code>lib</code> functions normally. We then import that new
derivation which we assign to <code>pkgs-unstable</code>. Now we can use <code>pkgs-unstable</code> to access the
derivation which we assign to <code>pkgs-unstable</code>. Now we can use <code>pkgs-unstable</code> to access the
Ghidra 11.2 package, as well as any other packages normally available in nixpkgs.
Ghidra 11.2 package, as well as any other packages normally available in nixpkgs.
Line 58: Line 59:
The following are resources that go into more depth on this topic.
The following are resources that go into more depth on this topic.


# [https://ertt.ca/nix/patch-nixpkgs/ Patching <nixpkgs>]
* [https://ertt.ca/nix/patch-nixpkgs/ Patching <nixpkgs>]