2024-10-08 18:37:17 +02:00
|
|
|
# Copyright Tom Hubrecht, (2023-2024)
|
2024-12-12 14:41:43 +01:00
|
|
|
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
|
2024-10-08 18:37:17 +02:00
|
|
|
#
|
2024-12-12 14:41:43 +01:00
|
|
|
# SPDX-License-Identifier: EUPL-1.2
|
2024-10-08 18:37:17 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
patchFile,
|
|
|
|
excludeGitHubManual ? true,
|
|
|
|
fetchers ? { },
|
|
|
|
}:
|
|
|
|
|
|
|
|
rec {
|
|
|
|
base =
|
|
|
|
{ pkgs }:
|
|
|
|
rec {
|
|
|
|
mkUrlPatch =
|
|
|
|
attrs:
|
|
|
|
pkgs.fetchpatch (
|
|
|
|
{
|
2024-10-08 20:49:26 +02:00
|
|
|
hash = pkgs.lib.fakeHash;
|
2024-10-08 18:37:17 +02:00
|
|
|
}
|
|
|
|
// attrs
|
2024-10-08 20:49:26 +02:00
|
|
|
// (pkgs.lib.optionalAttrs (excludeGitHubManual && !(builtins.hasAttr "includes" attrs)) {
|
2024-10-08 18:37:17 +02:00
|
|
|
excludes = (attrs.excludes or [ ]) ++ [ "nixos/doc/manual/*" ];
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
mkGitHubPatch =
|
|
|
|
{ id, ... }@attrs:
|
|
|
|
mkUrlPatch (
|
|
|
|
(builtins.removeAttrs attrs [ "id" ])
|
|
|
|
// {
|
|
|
|
url = "https://github.com/NixOS/nixpkgs/pull/${builtins.toString id}.diff";
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
mkCommitPatch =
|
|
|
|
{ sha, ... }@attrs:
|
|
|
|
mkUrlPatch (
|
|
|
|
(builtins.removeAttrs attrs [ "sha" ])
|
|
|
|
// {
|
|
|
|
url = "https://github.com/NixOS/nixpkgs/commit/${builtins.toString sha}.diff";
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
patchFunctions = {
|
|
|
|
commit = mkCommitPatch;
|
|
|
|
github = mkGitHubPatch;
|
|
|
|
remote = pkgs.fetchpatch;
|
|
|
|
static = attrs: attrs.path;
|
|
|
|
url = mkUrlPatch;
|
|
|
|
} // fetchers;
|
|
|
|
|
|
|
|
mkPatch =
|
|
|
|
{
|
|
|
|
_type ? "github",
|
|
|
|
...
|
|
|
|
}@attrs:
|
|
|
|
if builtins.hasAttr _type patchFunctions then
|
|
|
|
patchFunctions.${_type} (builtins.removeAttrs attrs [ "_type" ])
|
|
|
|
else
|
|
|
|
throw "Unknown patch type: ${builtins.toString _type}.";
|
|
|
|
|
|
|
|
mkPatches = v: builtins.map mkPatch ((import patchFile).${v} or [ ]);
|
|
|
|
|
|
|
|
applyPatches =
|
|
|
|
{
|
|
|
|
src,
|
|
|
|
name,
|
|
|
|
patches ? mkPatches name,
|
|
|
|
}:
|
|
|
|
if patches == [ ] then
|
|
|
|
src
|
|
|
|
else
|
|
|
|
pkgs.applyPatches {
|
|
|
|
inherit patches src;
|
|
|
|
|
|
|
|
name = "${name}-patched";
|
|
|
|
};
|
2024-10-08 20:49:26 +02:00
|
|
|
|
|
|
|
applyPatches' = name: src: applyPatches { inherit name src; };
|
2024-10-08 18:37:17 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
mkNixpkgsSrc = { src, name }: (base { pkgs = import src { }; }).applyPatches { inherit src name; };
|
|
|
|
}
|