2024-12-07 16:31:33 +01:00
{
2025-05-19 22:37:05 +02:00
callPackage ,
2024-12-07 16:31:33 +01:00
lib ,
jq ,
runCommand ,
writeText ,
2025-04-01 10:27:06 +02:00
python3 ,
2024-12-07 16:31:33 +01:00
} :
2024-11-28 22:57:12 +01:00
{
2025-05-18 15:31:48 +02:00
combinedDir ,
2024-11-28 22:57:12 +01:00
touchedFilesJson ,
2025-05-15 17:24:53 -04:00
githubAuthorId ,
2025-04-13 22:23:32 -07:00
byName ? false ,
2024-11-28 22:57:12 +01:00
} :
2024-12-07 16:31:33 +01:00
let
2024-12-09 23:22:12 +01:00
/*
Derivation that computes which packages are affected ( added , changed or removed ) between two revisions of nixpkgs .
Note : " p l a t f o r m s " are " x 8 6 _ 6 4 - l i n u x " , " a a r c h 6 4 - d a r w i n " , . . .
- - -
Inputs :
2025-05-18 21:21:44 +02:00
- beforeDir , afterDir : The evaluation result from before and after the change .
2024-12-09 23:22:12 +01:00
They can be obtained by running ` nix-build - A ci . eval . full ` on both revisions .
- - -
Outputs :
- changed-paths . json : Various information about the changes :
{
attrdiff : {
added : [ " p a c k a g e 1 " ] ,
changed : [ " p a c k a g e 2 " , " p a c k a g e 3 " ] ,
removed : [ " p a c k a g e 4 " ] ,
} ,
labels : [
" 1 0 . r e b u i l d - d a r w i n : 1 - 1 0 " ,
" 1 0 . r e b u i l d - l i n u x : 1 - 1 0 "
] ,
rebuildsByKernel : {
darwin : [ " p a c k a g e 1 " , " p a c k a g e 2 " ] ,
linux : [ " p a c k a g e 1 " , " p a c k a g e 2 " , " p a c k a g e 3 " ]
} ,
rebuildCountByKernel : {
darwin : 2 ,
linux : 3 ,
} ,
rebuildsByPlatform : {
aarch64-darwin : [ " p a c k a g e 1 " , " p a c k a g e 2 " ] ,
aarch64-linux : [ " p a c k a g e 1 " , " p a c k a g e 2 " ] ,
x86_64-linux : [ " p a c k a g e 1 " , " p a c k a g e 2 " , " p a c k a g e 3 " ] ,
x86_64-darwin : [ " p a c k a g e 1 " ] ,
} ,
}
- step-summary . md : A markdown render of the changes
- - -
Implementation details :
Helper functions can be found in ./utils.nix.
Two main " t y p e s " are important :
- ` packagePlatformPath ` : A string of the form " < P A C K A G E _ P A T H > . < P L A T F O R M > "
Example : " p y t h o n 3 1 2 P a c k a g e s . n u m p y . x 8 6 _ 6 4 - l i n u x "
- ` packagePlatformAttr ` : An attrs representation of a packagePlatformPath :
Example : { name = " p y t h o n 3 1 2 P a c k a g e s . n u m p y " ; platform = " x 8 6 _ 6 4 - l i n u x " ; }
* /
2024-12-07 16:31:33 +01:00
inherit ( import ./utils.nix { inherit lib ; } )
groupByKernel
2024-12-09 23:22:12 +01:00
convertToPackagePlatformAttrs
groupByPlatform
2024-12-07 16:31:33 +01:00
extractPackageNames
getLabels
;
2024-12-09 23:22:12 +01:00
# Attrs
# - keys: "added", "changed" and "removed"
# - values: lists of `packagePlatformPath`s
2025-05-18 15:31:48 +02:00
diffAttrs = builtins . fromJSON ( builtins . readFile " ${ combinedDir } / c o m b i n e d - d i f f . j s o n " ) ;
2024-12-07 16:31:33 +01:00
2025-01-27 22:44:51 +01:00
rebuilds = diffAttrs . added ++ diffAttrs . changed ;
2024-11-28 22:57:12 +01:00
rebuildsPackagePlatformAttrs = convertToPackagePlatformAttrs rebuilds ;
2024-12-07 16:31:33 +01:00
changed-paths =
let
2024-12-09 23:22:12 +01:00
rebuildsByPlatform = groupByPlatform rebuildsPackagePlatformAttrs ;
rebuildsByKernel = groupByKernel rebuildsPackagePlatformAttrs ;
2024-12-07 16:31:33 +01:00
rebuildCountByKernel = lib . mapAttrs (
kernel : kernelRebuilds : lib . length kernelRebuilds
) rebuildsByKernel ;
in
writeText " c h a n g e d - p a t h s . j s o n " (
builtins . toJSON {
2024-12-09 23:22:12 +01:00
attrdiff = lib . mapAttrs ( _ : extractPackageNames ) diffAttrs ;
inherit
rebuildsByPlatform
rebuildsByKernel
rebuildCountByKernel
;
2024-12-30 20:01:31 +01:00
labels =
( getLabels rebuildCountByKernel )
# Adds "10.rebuild-*-stdenv" label if the "stdenv" attribute was changed
++ lib . mapAttrsToList ( kernel : _ : " 1 0 . r e b u i l d - ${ kernel } - s t d e n v " ) (
lib . filterAttrs ( _ : kernelRebuilds : kernelRebuilds ? " s t d e n v " ) rebuildsByKernel
2025-05-15 17:24:53 -04:00
)
# Adds the "11.by: package-maintainer" label if all of the packages directly
# changed are maintained by the PR's author. (https://github.com/NixOS/ofborg/blob/df400f44502d4a4a80fa283d33f2e55a4e43ee90/ofborg/src/tagger.rs#L83-L88)
++ lib . optional (
maintainers ? ${ githubAuthorId }
&& lib . all ( lib . flip lib . elem maintainers . ${ githubAuthorId } ) (
lib . flatten ( lib . attrValues maintainers )
)
) " 1 1 . b y : p a c k a g e - m a i n t a i n e r " ;
2024-12-07 16:31:33 +01:00
}
) ;
2024-11-28 22:57:12 +01:00
2025-05-19 22:37:05 +02:00
maintainers = callPackage ./maintainers.nix { } {
2025-01-27 22:44:51 +01:00
changedattrs = lib . attrNames ( lib . groupBy ( a : a . name ) rebuildsPackagePlatformAttrs ) ;
2024-11-28 22:57:12 +01:00
changedpathsjson = touchedFilesJson ;
2025-04-13 22:23:32 -07:00
inherit byName ;
2024-11-28 22:57:12 +01:00
} ;
2024-12-07 16:31:33 +01:00
in
runCommand " c o m p a r e "
{
2025-04-01 10:27:06 +02:00
nativeBuildInputs = [
jq
( python3 . withPackages (
ps : with ps ; [
numpy
pandas
scipy
]
) )
] ;
2024-11-28 22:57:12 +01:00
maintainers = builtins . toJSON maintainers ;
passAsFile = [ " m a i n t a i n e r s " ] ;
2025-04-01 10:27:06 +02:00
env = {
2025-05-18 15:31:48 +02:00
BEFORE_DIR = " ${ combinedDir } / b e f o r e " ;
AFTER_DIR = " ${ combinedDir } / a f t e r " ;
2025-04-01 10:27:06 +02:00
} ;
2024-12-07 16:31:33 +01:00
}
''
mkdir $ out
cp $ { changed-paths } $ out/changed-paths.json
2025-04-01 10:27:06 +02:00
2025-04-01 10:27:06 +02:00
if jq - e ' ( . attrdiff . added | length = = 0 ) and ( . attrdiff . removed | length = = 0 ) ' " ${ changed-paths } " > /dev/null ; then
# Chunks have changed between revisions
# We cannot generate a performance comparison
{
echo
echo " # P e r f o r m a n c e c o m p a r i s o n "
echo
echo " T h i s c o m p a r e s t h e p e r f o r m a n c e o f t h i s b r a n c h a g a i n s t i t s p u l l r e q u e s t b a s e b r a n c h ( e . g . , ' m a s t e r ' ) "
echo
echo " F o r f u r t h e r h e l p p l e a s e r e f e r t o : [ c i / R E A D M E . m d ] ( h t t p s : / / g i t h u b . c o m / N i x O S / n i x p k g s / b l o b / m a s t e r / c i / R E A D M E . m d ) "
echo
} > > $ out/step-summary.md
python3 $ { ./cmp-stats.py } > > $ out/step-summary.md
2025-05-01 23:02:38 +02:00
2025-04-01 10:27:06 +02:00
else
# Package chunks are the same in both revisions
# We can use the to generate a performance comparison
{
echo
echo " # P e r f o r m a n c e C o m p a r i s o n "
echo
echo " P e r f o r m a n c e s t a t s w e r e s k i p p e d b e c a u s e t h e p a c k a g e s e t s d i f f e r b e t w e e n t h e t w o r e v i s i o n s . "
echo
echo " F o r f u r t h e r h e l p p l e a s e r e f e r t o : [ c i / R E A D M E . m d ] ( h t t p s : / / g i t h u b . c o m / N i x O S / n i x p k g s / b l o b / m a s t e r / c i / R E A D M E . m d ) "
} > > $ out/step-summary.md
fi
2025-05-31 14:25:49 +02:00
{
echo
echo " # P a c k a g e s "
echo
jq - r - f $ { ./generate-step-summary.jq } < $ { changed-paths }
} > > $ out/step-summary.md
2025-04-01 10:27:06 +02:00
cp " $ m a i n t a i n e r s P a t h " " $ o u t / m a i n t a i n e r s . j s o n "
2024-12-07 16:31:33 +01:00
''