'''
This script generates a .nix file containing all dependencies specified in the
special lock file. The .nix file also contains the derivation "pubCache", which can
be used as the path in the PUB_CACHE environment variable.
'''
import sys
import yaml
import urllib.parse
def generate_derivation(package):
name = package['description']['name']
sha = package['sha256']
version = package['version']
url = ''
if 'archive_url' in package:
url = package['archive_url']
else:
base_url = package['description']['url']
url = f'{base_url}/packages/{name}/versions/{version}.tar.gz'
return f'''
{name} = fetchzip {{
sha256 = "{sha}";
url = "{url}";
stripRoot = false;
extension = "tar.gz";
}};
'''
def main():
if len(sys.argv) != 4:
print('Usage: lock2nix.py