From fd27888c61a7069fd0ccf8089fe1f974dd0fe152 Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Tue, 10 Sep 2024 08:41:15 -0700 Subject: [PATCH] maintainers: add targeted fix for missing pkgs/by-name/.../package.nix files to maintainers/scripts/build.nix --- maintainers/scripts/build.nix | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/maintainers/scripts/build.nix b/maintainers/scripts/build.nix index ca401700b4a6..0783651df8f4 100644 --- a/maintainers/scripts/build.nix +++ b/maintainers/scripts/build.nix @@ -12,7 +12,27 @@ # nix-build build.nix --argstr maintainer --argstr system aarch64-linux let - pkgs = import ./../../default.nix (removeAttrs args [ "maintainer" ]); + # This avoids a common situation for maintainers, where due to Git's behavior of not tracking + # directories, they have an empty directory somewhere in `pkgs/by-name`. Because that directory + # exists, `pkgs/top-level/by-name-overlay.nix` picks it up and attempts to read `package.nix` out + # of it... which doesn't exist, since it's empty. + # + # We don't want to run the code below on every instantiation of `nixpkgs`, as the `pkgs/by-name` + # eval machinery is quite performance sensitive. So we use the internals of the `by-name` overlay + # to implement our own way to avoid an evaluation failure for this script. + # + # See for more motivation for this code block. + overlay = self: super: { + _internalCallByNamePackageFile = + file: if builtins.pathExists file then super._internalCallByNamePackageFile file else null; + }; + + nixpkgsArgs = removeAttrs args [ "maintainer" "overlays" ] // { + overlays = args.overlays or [] ++ [ overlay ]; + }; + + pkgs = import ./../../default.nix nixpkgsArgs; + maintainer_ = pkgs.lib.maintainers.${maintainer}; packagesWith = cond: return: set: (pkgs.lib.flatten