nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 174 lines 4.8 kB view raw
1{ 2 lib, 3 callPackage, 4 fetchurl, 5 fetchgit, 6 runCommand, 7}: 8 9{ 10 # The source directory of the package. 11 src, 12 13 # The package subdirectory within src. 14 # Useful if the package references sibling packages with relative paths. 15 packageRoot ? ".", 16 17 # The pubspec.lock file, in attribute set form. 18 pubspecLock, 19 20 # Hashes for Git dependencies. 21 # Pub does not record these itself, so they must be manually provided. 22 gitHashes ? { }, 23 24 # Functions to generate SDK package sources. 25 # The function names should match the SDK names, and the package name is given as an argument. 26 sdkSourceBuilders ? { }, 27 28 # Functions that create custom package source derivations. 29 # 30 # The function names should match the package names, and the package version, 31 # source, and source files are given in an attribute set argument. 32 # 33 # The passthru of the source derivation should be propagated. 34 customSourceBuilders ? { }, 35}: 36 37let 38 dependencyVersions = builtins.mapAttrs (name: details: details.version) pubspecLock.packages; 39 40 dependencyTypes = { 41 "direct main" = "main"; 42 "direct dev" = "dev"; 43 "direct overridden" = "overridden"; 44 "transitive" = "transitive"; 45 }; 46 47 dependencies = lib.foldlAttrs ( 48 dependencies: name: details: 49 dependencies 50 // { 51 ${dependencyTypes.${details.dependency}} = 52 dependencies.${dependencyTypes.${details.dependency}} 53 ++ [ name ]; 54 } 55 ) (lib.genAttrs (builtins.attrValues dependencyTypes) (dependencyType: [ ])) pubspecLock.packages; 56 57 # fetchTarball fails with "tarball contains an unexpected number of top-level files". This is a workaround. 58 # https://discourse.nixos.org/t/fetchtarball-with-multiple-top-level-directories-fails/20556 59 mkHostedDependencySource = 60 name: details: 61 let 62 archive = fetchurl { 63 name = "pub-${name}-${details.version}.tar.gz"; 64 url = "${details.description.url}/packages/${details.description.name}/versions/${details.version}.tar.gz"; 65 sha256 = details.description.sha256; 66 }; 67 in 68 runCommand "pub-${name}-${details.version}" { passthru.packageRoot = "."; } '' 69 mkdir -p "$out" 70 tar xf '${archive}' -C "$out" 71 ''; 72 73 mkGitDependencySource = 74 name: details: 75 (fetchgit { 76 name = "pub-${name}-${details.version}"; 77 url = details.description.url; 78 rev = details.description.resolved-ref; 79 hash = 80 gitHashes.${name} 81 or (throw "A Git hash is required for ${name}! Set to an empty string to obtain it."); 82 }).overrideAttrs 83 ( 84 { 85 passthru ? { }, 86 ... 87 }: 88 { 89 passthru = passthru // { 90 packageRoot = details.description.path; 91 }; 92 } 93 ); 94 95 mkPathDependencySource = 96 name: details: 97 assert lib.assertMsg details.description.relative 98 "Only relative paths are supported - ${name} has an absolue path!"; 99 ( 100 if lib.isDerivation src then 101 src 102 else 103 (runCommand "pub-${name}-${details.version}" { } ''cp -r '${src}' "$out"'') 104 ).overrideAttrs 105 ( 106 { 107 passthru ? { }, 108 ... 109 }: 110 { 111 passthru = passthru // { 112 packageRoot = "${packageRoot}/${details.description.path}"; 113 }; 114 } 115 ); 116 117 mkSdkDependencySource = 118 name: details: 119 (sdkSourceBuilders.${details.description} 120 or (throw "No SDK source builder has been given for ${details.description}!") 121 ) 122 name; 123 124 addDependencySourceUtils = 125 dependencySource: details: 126 dependencySource.overrideAttrs ( 127 { passthru, ... }: 128 { 129 passthru = passthru // { 130 inherit (details) version; 131 }; 132 } 133 ); 134 135 sourceBuilders = 136 callPackage ../../../development/compilers/dart/package-source-builders { } // customSourceBuilders; 137 138 dependencySources = lib.filterAttrs (name: src: src != null) ( 139 builtins.mapAttrs ( 140 name: details: 141 (sourceBuilders.${name} or ({ src, ... }: src)) { 142 inherit (details) version source; 143 src = ( 144 (addDependencySourceUtils ( 145 ( 146 { 147 "hosted" = mkHostedDependencySource; 148 "git" = mkGitDependencySource; 149 "path" = mkPathDependencySource; 150 "sdk" = mkSdkDependencySource; 151 } 152 .${details.source} 153 name 154 ) 155 details 156 )) 157 details 158 ); 159 } 160 ) pubspecLock.packages 161 ); 162in 163{ 164 inherit 165 # An attribute set of dependency categories to package name lists. 166 dependencies 167 168 # An attribute set of package names to their versions. 169 dependencyVersions 170 171 # An attribute set of package names to their sources. 172 dependencySources 173 ; 174}