36bf6afd42
Be able to build arbitrary Julia environments in Nixpkgs, in the same style as python.withPackages.
68 lines
1.9 KiB
Python
Executable File
68 lines
1.9 KiB
Python
Executable File
|
|
import json
|
|
from pathlib import Path
|
|
import re
|
|
import shutil
|
|
import sys
|
|
import toml
|
|
import util
|
|
import yaml
|
|
|
|
|
|
registry_path = Path(sys.argv[1])
|
|
package_overrides = json.loads(sys.argv[2])
|
|
desired_packages_path = Path(sys.argv[3])
|
|
out_path = Path(sys.argv[4])
|
|
|
|
with open(desired_packages_path, "r") as f:
|
|
desired_packages = yaml.safe_load(f) or []
|
|
|
|
registry = toml.load(registry_path / "Registry.toml")
|
|
|
|
def ensure_version_valid(version):
|
|
"""
|
|
Ensure a version string is a valid Julia-parsable version.
|
|
It doesn't really matter what it looks like as it's just used for overrides.
|
|
"""
|
|
return re.sub('[^0-9\.]','', version)
|
|
|
|
with open(out_path, "w") as f:
|
|
f.write("{fetchgit}:\n")
|
|
f.write("{\n")
|
|
for pkg in desired_packages:
|
|
uuid = pkg["uuid"]
|
|
|
|
if pkg["name"] in package_overrides:
|
|
treehash = util.get_commit_info(package_overrides[pkg["name"]])["tree"]
|
|
f.write(f""" "{uuid}" = {{
|
|
src = null; # Overridden: will fill in later
|
|
name = "{pkg["name"]}";
|
|
version = "{ensure_version_valid(pkg["version"])}";
|
|
treehash = "{treehash}";
|
|
}};\n""")
|
|
elif uuid in registry["packages"]:
|
|
registry_info = registry["packages"][uuid]
|
|
path = registry_info["path"]
|
|
packageToml = toml.load(registry_path / path / "Package.toml")
|
|
|
|
all_versions = toml.load(registry_path / path / "Versions.toml")
|
|
if not pkg["version"] in all_versions: continue
|
|
version_to_use = all_versions[pkg["version"]]
|
|
|
|
repo = packageToml["repo"]
|
|
f.write(f""" "{uuid}" = {{
|
|
src = fetchgit {{
|
|
url = "{repo}";
|
|
rev = "{version_to_use["git-tree-sha1"]}";
|
|
sha256 = "{version_to_use["nix-sha256"]}";
|
|
}};
|
|
name = "{pkg["name"]}";
|
|
version = "{pkg["version"]}";
|
|
treehash = "{version_to_use["git-tree-sha1"]}";
|
|
}};\n""")
|
|
else:
|
|
# print("Warning: couldn't figure out what to do with pkg in sources_nix.py", pkg)
|
|
pass
|
|
|
|
f.write("}")
|