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