feat: Make moxxmpp docs buildable using flakes
This commit is contained in:
68
scripts/lock2nix.py
Normal file
68
scripts/lock2nix.py
Normal file
@@ -0,0 +1,68 @@
|
||||
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 <input lock> <output nix> <package name>')
|
||||
exit(1)
|
||||
|
||||
input_file = sys.argv[1]
|
||||
output_file = sys.argv[2]
|
||||
package_name = sys.argv[3]
|
||||
|
||||
with open(input_file, 'r') as f:
|
||||
data = yaml.safe_load(f.read())
|
||||
|
||||
with open(output_file, 'w') as f:
|
||||
f.write('# GENERATED BY LOCK2NIX.py\n')
|
||||
f.write('# DO NOT EDIT BY HAND\n')
|
||||
f.write('{fetchzip, runCommand} : rec {')
|
||||
steps = ''
|
||||
for package in data['packages']:
|
||||
try:
|
||||
f.write(generate_derivation(data['packages'][package]))
|
||||
except ex:
|
||||
print(f'Failed with {ex} for package {package}')
|
||||
|
||||
print(package)
|
||||
source = data['packages'][package]['source']
|
||||
prefix = urllib.parse.quote(
|
||||
data['packages'][package]['description']['url'][8:],
|
||||
safe='',
|
||||
).replace('%2F', '%47')
|
||||
name = data['packages'][package]['description']['name']
|
||||
version = data['packages'][package]['version']
|
||||
steps += f'''
|
||||
mkdir -p $out/{source}/{prefix}
|
||||
ln -s ${{{package}}} $out/{source}/{prefix}/{name}-{version}
|
||||
'''
|
||||
|
||||
f.write(f'''
|
||||
pubCache = runCommand "{package_name}-pub-cache" {{}} ''{steps}'';
|
||||
''')
|
||||
f.write('\n}')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
64
scripts/pubspec2lock.py
Normal file
64
scripts/pubspec2lock.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import sys
|
||||
import subprocess
|
||||
import urllib
|
||||
import yaml
|
||||
import requests
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 3:
|
||||
print('Usage: pubspec2lock.py <input> <output>')
|
||||
exit(1)
|
||||
|
||||
input_file = sys.argv[1]
|
||||
output_file = sys.argv[2]
|
||||
|
||||
with open(input_file, 'r') as f:
|
||||
data = yaml.safe_load(f.read())
|
||||
|
||||
result = {
|
||||
'packages': {}
|
||||
}
|
||||
for package_name in data['packages']:
|
||||
print(package_name)
|
||||
package = data['packages'][package_name]
|
||||
cleaned_url = package["description"]["url"]
|
||||
if cleaned_url[-1] == '/':
|
||||
cleaned_url = cleaned_url[:-1]
|
||||
|
||||
latest = requests.get(
|
||||
f'{cleaned_url}/api/packages/{package_name}',
|
||||
headers={
|
||||
'Accept': 'application/vnd.pub.v2+json',
|
||||
},
|
||||
)
|
||||
|
||||
latest_data = None
|
||||
try:
|
||||
latest_data = latest.json()
|
||||
except:
|
||||
print(latest.text)
|
||||
exit(1)
|
||||
|
||||
for version_data in latest_data['versions']:
|
||||
if version_data['version'] == package['version']:
|
||||
package['archive_url'] = version_data['archive_url']
|
||||
|
||||
p = subprocess.run([
|
||||
'nix-prefetch-url',
|
||||
'--unpack',
|
||||
urllib.parse.unquote(version_data['archive_url']),
|
||||
], capture_output=True)
|
||||
sha256 = p.stdout.decode('utf8')[:-1]
|
||||
|
||||
package['sha256'] = sha256
|
||||
break
|
||||
|
||||
result['packages'][package_name] = package
|
||||
|
||||
with open(output_file, 'w') as f:
|
||||
f.write('# CREATED BY pubspec2lock.py\n')
|
||||
f.write('# DO NOT EDIT BY HAND\n')
|
||||
f.write(yaml.dump(result))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user