build-support/vm: don't depend on the "unix" module (#375355)
[NixPkgs.git] / pkgs / development / julia-modules / package-closure.nix
bloba393a2f49427091fe3b265a55d62d834952af497
2   lib,
3   julia,
4   python3,
5   runCommand,
7   augmentedRegistry,
8   packageNames,
9   packageOverrides,
10   packageImplications,
13 let
14   juliaExpression = packageNames: ''
15     import Pkg
16     Pkg.Registry.add(Pkg.RegistrySpec(path="${augmentedRegistry}"))
18     import Pkg.Types: Context, PackageSpec
20     input = ${lib.generators.toJSON { } packageNames}
22     if isfile("extra_package_names.txt")
23         append!(input, readlines("extra_package_names.txt"))
24     end
26     input = unique(input)
28     println("Resolving packages: " * join(input, " "))
30     pkgs = [PackageSpec(pkg) for pkg in input]
32     ctx = Context()
34     overrides = Dict{String, String}(${
35       builtins.concatStringsSep ", " (
36         lib.mapAttrsToList (name: path: ''"${name}" => "${path}"'') packageOverrides
37       )
38     })
39     ${builtins.readFile ./resolve_packages.jl}
41     open(ENV["out"], "w") do io
42         for spec in pkgs
43             println(io, "- name: " * spec.name)
44             println(io, "  uuid: " * string(spec.uuid))
45             println(io, "  version: " * string(spec.version))
46             if endswith(spec.name, "_jll") && haskey(deps_map, spec.uuid)
47                 println(io, "  depends_on: ")
48                 for (dep_name, dep_uuid) in pairs(deps_map[spec.uuid])
49                     println(io, "    \"$(dep_name)\": \"$(dep_uuid)\"")
50                 end
51             end
52         end
53     end
54   '';
57 runCommand "julia-package-closure.yml"
58   {
59     buildInputs = [
60       julia
61       (python3.withPackages (ps: with ps; [ pyyaml ]))
62     ];
63   }
64   ''
65     mkdir home
66     export HOME=$(pwd)/home
68     echo "Resolving Julia packages with the following inputs"
69     echo "Julia: ${julia}"
70     echo "Registry: ${augmentedRegistry}"
72     # Prevent a warning where Julia tries to download package server info
73     export JULIA_PKG_SERVER=""
75     julia -e '${juliaExpression packageNames}';
77     # See if we need to add any extra package names based on the closure
78     # and the packageImplications
79     python ${./python}/find_package_implications.py "$out" '${
80       lib.generators.toJSON { } packageImplications
81     }' extra_package_names.txt
83     if [ -f extra_package_names.txt ]; then
84       echo "Re-resolving with additional package names"
85       julia -e '${juliaExpression packageNames}';
86     fi
87   ''