|
9 | 9 |
|
10 | 10 | , settings |
11 | 11 | , settingsSchema |
| 12 | +, subPackageSettingsSchema |
12 | 13 | }: |
13 | 14 |
|
14 | 15 | with { inherit (settings) packages; }; |
|
23 | 24 | displayName = name + " " + python3.version; |
24 | 25 | kernelName = "python3"; |
25 | 26 |
|
26 | | - packageOptions = python3.pkgs; |
27 | | - packageSearch = common.searcher packageOptions; |
| 27 | + packageOptionsBase = python3.pkgs; |
| 28 | + packageSearch = common.searcher packageOptionsBase; |
| 29 | + |
| 30 | + # For makeEnvironment.nix's chooseMeta lookup: lazily add settingsSchema to packages |
| 31 | + # that have optional-dependencies, so the UI knows extras are available. |
| 32 | + # Nix's laziness means only actually-accessed packages get evaluated. |
| 33 | + packageOptions = lib.mapAttrs (_name: pkg: |
| 34 | + if (builtins.tryEval (pkg ? optional-dependencies && pkg.optional-dependencies != {})).value or false |
| 35 | + then pkg // { inherit subPackageSettingsSchema; settingsSchema = subPackageSettingsSchema; } |
| 36 | + else pkg |
| 37 | + ) packageOptionsBase; |
| 38 | + |
| 39 | + resolvePackage = p: |
| 40 | + let |
| 41 | + pname = common.packageName p; |
| 42 | + basePkg = builtins.getAttr pname packageOptionsBase; |
| 43 | + extras = if lib.isAttrs p then (p.extras or []) else []; |
| 44 | + extraPkgs = lib.concatMap (extra: |
| 45 | + basePkg.optional-dependencies.${extra} or [] |
| 46 | + ) extras; |
| 47 | + in [basePkg] ++ extraPkgs; |
| 48 | + |
28 | 49 | allPackages = |
29 | | - [packageOptions.ipykernel packageOptions.ipywidgets] |
30 | | - ++ map (x: builtins.getAttr x packageOptions) (map common.packageName packages) |
| 50 | + [packageOptionsBase.ipykernel packageOptionsBase.ipywidgets] |
| 51 | + ++ lib.concatMap resolvePackage packages |
31 | 52 | ; |
32 | 53 |
|
33 | 54 | pythonWithPackages = f: python3.withPackages (_: allPackages ++ f packageOptions); |
|
0 commit comments