| 
									
										
										
										
											2009-03-30 13:22:19 +00:00
										 |  |  | /* Some functions for manipulating meta attributes, as well as the
 | 
					
						
							|  |  |  |    name attribute. */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-28 20:05:35 -04:00
										 |  |  | { lib }: | 
					
						
							| 
									
										
										
										
											2013-12-26 04:22:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 13:22:19 +00:00
										 |  |  | rec { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Add to or override the meta attributes of the given
 | 
					
						
							|  |  |  |      derivation. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |      Example: | 
					
						
							|  |  |  |        addMetaAttrs {description = "Bla blah";} somePkg | 
					
						
							|  |  |  |   */ | 
					
						
							|  |  |  |   addMetaAttrs = newAttrs: drv: | 
					
						
							| 
									
										
										
										
											2014-01-20 14:54:50 +01:00
										 |  |  |     drv // { meta = (drv.meta or {}) // newAttrs; }; | 
					
						
							| 
									
										
										
										
											2009-03-30 13:22:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-27 20:44:00 +03:00
										 |  |  |   /* Disable Hydra builds of given derivation.
 | 
					
						
							|  |  |  |   */ | 
					
						
							|  |  |  |   dontDistribute = drv: addMetaAttrs { hydraPlatforms = []; } drv; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 13:22:19 +00:00
										 |  |  |   /* Change the symbolic name of a package for presentation purposes
 | 
					
						
							|  |  |  |      (i.e., so that nix-env users can tell them apart). | 
					
						
							|  |  |  |   */ | 
					
						
							|  |  |  |   setName = name: drv: drv // {inherit name;}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* Like `setName', but takes the previous name as an argument.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |      Example: | 
					
						
							|  |  |  |        updateName (oldName: oldName + "-experimental") somePkg | 
					
						
							|  |  |  |   */ | 
					
						
							|  |  |  |   updateName = updater: drv: drv // {name = updater (drv.name);}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-10 15:01:56 +01:00
										 |  |  |   /* Append a suffix to the name of a package (before the version
 | 
					
						
							|  |  |  |      part). */ | 
					
						
							|  |  |  |   appendToName = suffix: updateName (name: | 
					
						
							|  |  |  |     let x = builtins.parseDrvName name; in "${x.name}-${suffix}-${x.version}"); | 
					
						
							| 
									
										
										
										
											2009-03-30 13:22:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-18 08:26:13 +00:00
										 |  |  |   /* Apply a function to each derivation and only to derivations in an attrset.
 | 
					
						
							| 
									
										
										
										
											2013-12-26 04:22:29 +02:00
										 |  |  |   */ | 
					
						
							|  |  |  |   mapDerivationAttrset = f: set: lib.mapAttrs (name: pkg: if lib.isDerivation pkg then (f pkg) else pkg) set; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-18 08:26:13 +00:00
										 |  |  |   /* Set the nix-env priority of the package.
 | 
					
						
							|  |  |  |   */ | 
					
						
							|  |  |  |   setPrio = priority: addMetaAttrs { inherit priority; }; | 
					
						
							| 
									
										
										
										
											2013-12-26 04:22:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-30 13:22:19 +00:00
										 |  |  |   /* Decrease the nix-env priority of the package, i.e., other
 | 
					
						
							|  |  |  |      versions/variants of the package will be preferred. | 
					
						
							|  |  |  |   */ | 
					
						
							| 
									
										
										
										
											2018-11-18 08:26:13 +00:00
										 |  |  |   lowPrio = setPrio 10; | 
					
						
							| 
									
										
										
										
											2013-12-26 04:22:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Apply lowPrio to an attrset with derivations
 | 
					
						
							|  |  |  |   */ | 
					
						
							| 
									
										
										
										
											2014-01-20 14:54:50 +01:00
										 |  |  |   lowPrioSet = set: mapDerivationAttrset lowPrio set; | 
					
						
							| 
									
										
										
										
											2013-12-26 04:22:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 08:59:46 +00:00
										 |  |  |   /* Increase the nix-env priority of the package, i.e., this
 | 
					
						
							|  |  |  |      version/variant of the package will be preferred. | 
					
						
							|  |  |  |   */ | 
					
						
							| 
									
										
										
										
											2018-11-18 08:26:13 +00:00
										 |  |  |   hiPrio = setPrio (-10); | 
					
						
							| 
									
										
										
										
											2013-12-26 04:22:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Apply hiPrio to an attrset with derivations
 | 
					
						
							|  |  |  |   */ | 
					
						
							|  |  |  |   hiPrioSet = set: mapDerivationAttrset hiPrio set; | 
					
						
							| 
									
										
										
										
											2014-01-20 14:54:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-19 18:03:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Check to see if a platform is matched by the given `meta.platforms`
 | 
					
						
							|  |  |  |      element. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |      A `meta.platform` pattern is either | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |        1. (legacy) a system string. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |        2. (modern) a pattern for the platform `parsed` field. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |      We can inject these into a patten for the whole of a structured platform, | 
					
						
							|  |  |  |      and then match that. | 
					
						
							|  |  |  |   */ | 
					
						
							|  |  |  |   platformMatch = platform: elem: let | 
					
						
							|  |  |  |       pattern = | 
					
						
							|  |  |  |         if builtins.isString elem | 
					
						
							|  |  |  |         then { system = elem; } | 
					
						
							|  |  |  |         else { parsed = elem; }; | 
					
						
							|  |  |  |     in lib.matchAttrs pattern platform; | 
					
						
							| 
									
										
										
										
											2009-03-30 13:22:19 +00:00
										 |  |  | } |