at 25.11-pre 3.9 kB view raw
1# Almost directly vendored from https://github.com/NixOS/ofborg/blob/5a4e743f192fb151915fcbe8789922fa401ecf48/ofborg/src/maintainers.nix 2{ 3 changedattrs, 4 changedpathsjson, 5 byName ? false, 6}: 7let 8 pkgs = import ../../.. { 9 system = "x86_64-linux"; 10 config = { }; 11 overlays = [ ]; 12 }; 13 inherit (pkgs) lib; 14 15 changedpaths = builtins.fromJSON (builtins.readFile changedpathsjson); 16 17 anyMatchingFile = 18 filename: builtins.any (changed: lib.strings.hasSuffix changed filename) changedpaths; 19 20 anyMatchingFiles = files: builtins.any anyMatchingFile files; 21 22 enrichedAttrs = builtins.map (name: { 23 path = lib.splitString "." name; 24 name = name; 25 }) changedattrs; 26 27 validPackageAttributes = builtins.filter ( 28 pkg: 29 if (lib.attrsets.hasAttrByPath pkg.path pkgs) then 30 ( 31 let 32 value = lib.attrsets.attrByPath pkg.path null pkgs; 33 in 34 if (builtins.tryEval value).success then 35 if value != null then true else builtins.trace "${pkg.name} exists but is null" false 36 else 37 builtins.trace "Failed to access ${pkg.name} even though it exists" false 38 ) 39 else 40 builtins.trace "Failed to locate ${pkg.name}." false 41 ) enrichedAttrs; 42 43 attrsWithPackages = builtins.map ( 44 pkg: pkg // { package = lib.attrsets.attrByPath pkg.path null pkgs; } 45 ) validPackageAttributes; 46 47 attrsWithMaintainers = builtins.map ( 48 pkg: 49 let 50 meta = pkg.package.meta or { }; 51 in 52 pkg 53 // { 54 # TODO: Refactor this so we can ping entire teams instead of the individual members. 55 # Note that this will require keeping track of GH team IDs in "maintainers/teams.nix". 56 maintainers = meta.maintainers or [ ]; 57 } 58 ) attrsWithPackages; 59 60 relevantFilenames = 61 drv: 62 (lib.lists.unique ( 63 builtins.map (pos: lib.strings.removePrefix (toString ../..) pos.file) ( 64 builtins.filter (x: x != null) [ 65 ((drv.meta or { }).maintainersPosition or null) 66 ((drv.meta or { }).teamsPosition or null) 67 (builtins.unsafeGetAttrPos "src" drv) 68 # broken because name is always set by stdenv: 69 # # A hack to make `nix-env -qa` and `nix search` ignore broken packages. 70 # # TODO(@oxij): remove this assert when something like NixOS/nix#1771 gets merged into nix. 71 # name = assert validity.handled; name + lib.optionalString 72 #(builtins.unsafeGetAttrPos "name" drv) 73 (builtins.unsafeGetAttrPos "pname" drv) 74 (builtins.unsafeGetAttrPos "version" drv) 75 76 # Use ".meta.position" for cases when most of the package is 77 # defined in a "common" section and the only place where 78 # reference to the file with a derivation the "pos" 79 # attribute. 80 # 81 # ".meta.position" has the following form: 82 # "pkgs/tools/package-management/nix/default.nix:155" 83 # We transform it to the following: 84 # { file = "pkgs/tools/package-management/nix/default.nix"; } 85 { file = lib.head (lib.splitString ":" (drv.meta.position or "")); } 86 ] 87 ) 88 )); 89 90 attrsWithFilenames = builtins.map ( 91 pkg: pkg // { filenames = relevantFilenames pkg.package; } 92 ) attrsWithMaintainers; 93 94 attrsWithModifiedFiles = builtins.filter (pkg: anyMatchingFiles pkg.filenames) attrsWithFilenames; 95 96 listToPing = lib.concatMap ( 97 pkg: 98 builtins.map (maintainer: { 99 id = maintainer.githubId; 100 inherit (maintainer) github; 101 packageName = pkg.name; 102 dueToFiles = pkg.filenames; 103 }) pkg.maintainers 104 ) attrsWithModifiedFiles; 105 106 byMaintainer = lib.groupBy (ping: toString ping.${if byName then "github" else "id"}) listToPing; 107 108 packagesPerMaintainer = lib.attrsets.mapAttrs ( 109 maintainer: packages: builtins.map (pkg: pkg.packageName) packages 110 ) byMaintainer; 111in 112packagesPerMaintainer