at 25.11-pre 2.7 kB view raw
1{ 2 maintainer, 3 localSystem ? { 4 system = args.system or builtins.currentSystem; 5 }, 6 system ? localSystem.system, 7 crossSystem ? localSystem, 8 ... 9}@args: 10 11# based on update.nix 12# nix-build build.nix --argstr maintainer <yourname> 13 14# to build for aarch64-linux using boot.binfmt.emulatedSystems: 15# nix-build build.nix --argstr maintainer <yourname> --argstr system aarch64-linux 16 17let 18 # This avoids a common situation for maintainers, where due to Git's behavior of not tracking 19 # directories, they have an empty directory somewhere in `pkgs/by-name`. Because that directory 20 # exists, `pkgs/top-level/by-name-overlay.nix` picks it up and attempts to read `package.nix` out 21 # of it... which doesn't exist, since it's empty. 22 # 23 # We don't want to run the code below on every instantiation of `nixpkgs`, as the `pkgs/by-name` 24 # eval machinery is quite performance sensitive. So we use the internals of the `by-name` overlay 25 # to implement our own way to avoid an evaluation failure for this script. 26 # 27 # See <https://github.com/NixOS/nixpkgs/issues/338227> for more motivation for this code block. 28 overlay = self: super: { 29 _internalCallByNamePackageFile = 30 file: if builtins.pathExists file then super._internalCallByNamePackageFile file else null; 31 }; 32 33 nixpkgsArgs = 34 removeAttrs args [ 35 "maintainer" 36 "overlays" 37 ] 38 // { 39 overlays = args.overlays or [ ] ++ [ overlay ]; 40 }; 41 42 pkgs = import ./../../default.nix nixpkgsArgs; 43 44 maintainer_ = pkgs.lib.maintainers.${maintainer}; 45 packagesWith = 46 cond: return: set: 47 (pkgs.lib.flatten ( 48 pkgs.lib.mapAttrsToList ( 49 name: pkg: 50 let 51 result = builtins.tryEval ( 52 if pkgs.lib.isDerivation pkg && cond name pkg then 53 # Skip packages whose closure fails on evaluation. 54 # This happens for pkgs like `python27Packages.djangoql` 55 # that have disabled Python pkgs as dependencies. 56 builtins.seq pkg.outPath [ (return name pkg) ] 57 else if pkg.recurseForDerivations or false || pkg.recurseForRelease or false then 58 packagesWith cond return pkg 59 else 60 [ ] 61 ); 62 in 63 if result.success then result.value else [ ] 64 ) set 65 )); 66in 67packagesWith ( 68 name: pkg: 69 ( 70 if builtins.hasAttr "meta" pkg && builtins.hasAttr "maintainers" pkg.meta then 71 ( 72 if builtins.isList pkg.meta.maintainers then 73 builtins.elem maintainer_ pkg.meta.maintainers 74 else 75 maintainer_ == pkg.meta.maintainers 76 ) 77 else 78 false 79 ) 80) (name: pkg: pkg) pkgs