forked from DGNum/infrastructure
Tom Hubrecht
88d9b8c3e3
Signed-off-by: Tom Hubrecht <tom.hubrecht@dgnum.eu> Acked-by: Ryan Lahfa <ryan.lahfa@dgnum.eu> Acked-by: Maurice Debray <maurice.debray@dgnum.eu> Acked-by: Lubin Bailly <lubin.bailly@dgnum.eu> Acked-by: Jean-Marc Gailis <jean-marc.gailis@dgnum.eu> as the legal authority, at the time of writing, in DGNum. Acked-by: Elias Coppens <elias.coppens@dgnum.eu> as a member, at the time of writing, of the DGNum executive counsel.
85 lines
2.1 KiB
Nix
85 lines
2.1 KiB
Nix
# Copyright Tom Hubrecht, (2023-2024)
|
|
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
|
|
#
|
|
# SPDX-License-Identifier: EUPL-1.2
|
|
|
|
{
|
|
patchFile,
|
|
excludeGitHubManual ? true,
|
|
fetchers ? { },
|
|
}:
|
|
|
|
rec {
|
|
base =
|
|
{ pkgs }:
|
|
rec {
|
|
mkUrlPatch =
|
|
attrs:
|
|
pkgs.fetchpatch (
|
|
{
|
|
hash = pkgs.lib.fakeHash;
|
|
}
|
|
// attrs
|
|
// (pkgs.lib.optionalAttrs (excludeGitHubManual && !(builtins.hasAttr "includes" attrs)) {
|
|
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";
|
|
};
|
|
|
|
applyPatches' = name: src: applyPatches { inherit name src; };
|
|
};
|
|
|
|
mkNixpkgsSrc = { src, name }: (base { pkgs = import src { }; }).applyPatches { inherit src name; };
|
|
}
|