-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathjulia2nix
executable file
·42 lines (32 loc) · 1.68 KB
/
julia2nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p "python3"
import argparse
import os
from pathlib import Path
import shutil
import stat
import subprocess
def main():
script_dir = Path(os.path.dirname(os.path.realpath(__file__)))
parser = argparse.ArgumentParser(description="Generate Nix expressions from Julia Package.toml/Manifest.toml files")
parser.add_argument("-w", "--workers", type=int, default=8,
help="number of parallel workers to use for nix-prefetch-git calls")
parser.add_argument("-o", "--output-dir", type=str, default=".",
help="output directory for files (default: current working directory)")
args = parser.parse_args()
output_dir = Path(args.output_dir)
workers = args.workers
# Always copy the common code
shutil.copy(script_dir.joinpath("templates").joinpath("common.nix"), output_dir)
os.chmod(output_dir.joinpath("common.nix"), stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
# Only copy default.nix if it doesn't exist yet, since the user is meant to modify it
if not output_dir.joinpath("default.nix").exists():
shutil.copy(script_dir.joinpath("templates").joinpath("default.nix"), output_dir)
os.chmod(output_dir.joinpath("default.nix"), stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)
environment_dir = Path(".")
repo_url = "https://github.com/JuliaRegistries/General.git"
packages_nix = subprocess.check_output([script_dir.joinpath("gather_packages.py"), environment_dir, repo_url, str(workers)]).decode()
with open(output_dir.joinpath("packages.nix"), "w") as f:
f.write(packages_nix)
if __name__ == "__main__":
main()