# Copyright Tom Hubrecht, (2023-2024) # SPDX-FileCopyrightText: 2024 Tom Hubrecht # # 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; }; }