2024-06-15 04:02:23 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from pathlib import Path
|
|
|
|
import textwrap
|
|
|
|
import dataclasses
|
|
|
|
import requests
|
2024-07-19 19:22:25 +00:00
|
|
|
import subprocess
|
2024-06-15 04:02:23 +00:00
|
|
|
|
|
|
|
SYSTEMS = ['x86_64-linux', 'x86_64-darwin', 'aarch64-linux', 'aarch64-darwin']
|
|
|
|
|
|
|
|
@dataclasses.dataclass
|
|
|
|
class Package:
|
|
|
|
system: str
|
|
|
|
version: str
|
|
|
|
|
|
|
|
def url(self):
|
|
|
|
return f"https://releases.lix.systems/lix/lix-{self.version}/lix-{self.version}-{self.system}.tar.xz";
|
|
|
|
|
|
|
|
def variable_name(self):
|
|
|
|
system = self.system.replace('-', '_').upper()
|
|
|
|
return f'LIX_{system}_URL'
|
|
|
|
|
|
|
|
|
|
|
|
def make_urls_section(packages: list[Package]):
|
|
|
|
def one_item(package: Package):
|
|
|
|
return textwrap.dedent("""\
|
|
|
|
/// Default [`nix_package_url`](CommonSettings::nix_package_url) for {system}.
|
|
|
|
pub const {variable_name}: &str =
|
|
|
|
"{url}";
|
|
|
|
""").format(system=package.system, variable_name=package.variable_name(), url=package.url())
|
|
|
|
|
|
|
|
return '\n'.join(one_item(package) for package in packages)
|
|
|
|
|
|
|
|
def replace_section(old: str, section: str) -> str:
|
|
|
|
lines = []
|
|
|
|
eat = False
|
|
|
|
|
|
|
|
for line in old.splitlines():
|
|
|
|
next_eat = eat
|
|
|
|
|
|
|
|
if 'BEGIN GENERATE-URLS' in line.strip():
|
|
|
|
next_eat = True
|
|
|
|
elif 'END GENERATE-URLS' in line.strip():
|
|
|
|
lines.append(section)
|
|
|
|
eat = False
|
|
|
|
next_eat = False
|
|
|
|
|
|
|
|
if not eat:
|
|
|
|
lines.append(line)
|
|
|
|
eat = next_eat
|
|
|
|
|
|
|
|
return '\n'.join(lines)
|
|
|
|
|
|
|
|
def replace_in_file(file: Path, section: str):
|
|
|
|
new_file = replace_section(file.read_text(), section)
|
|
|
|
file.write_text(new_file)
|
|
|
|
|
|
|
|
|
|
|
|
def make_flake_url_section(version: str) -> str:
|
|
|
|
return f' url = "https://git.lix.systems/lix-project/lix/archive/{version}.tar.gz";'
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
import argparse
|
|
|
|
ap = argparse.ArgumentParser(description='Update the version of lix-installer')
|
|
|
|
|
|
|
|
ap.add_argument('new_version', help='The new version')
|
|
|
|
|
|
|
|
args = ap.parse_args()
|
|
|
|
|
|
|
|
settings_rs = Path('src/settings.rs')
|
|
|
|
packages = [Package(system, args.new_version) for system in SYSTEMS]
|
|
|
|
|
|
|
|
for package in packages:
|
|
|
|
resp = requests.head(package.url())
|
|
|
|
if resp.status_code != 200:
|
|
|
|
print(f'Warning: broken URL {package.url()} returns HTTP {resp.status_code}')
|
|
|
|
|
|
|
|
replace_in_file(settings_rs, make_urls_section(packages))
|
|
|
|
flake_nix = Path('flake.nix')
|
|
|
|
replace_in_file(flake_nix, make_flake_url_section(args.new_version))
|
|
|
|
|
2024-08-17 20:42:31 +00:00
|
|
|
# This is required to force Lix to update the lock file due to:
|
|
|
|
# https://git.lix.systems/lix-project/lix/issues/465
|
2024-07-19 19:22:25 +00:00
|
|
|
subprocess.run([
|
|
|
|
'nix',
|
|
|
|
'--extra-experimental-features',
|
|
|
|
'nix-command flakes',
|
|
|
|
'flake',
|
2024-08-17 20:42:31 +00:00
|
|
|
'update',
|
|
|
|
'lix',
|
2024-07-19 19:22:25 +00:00
|
|
|
])
|
|
|
|
|
2024-06-15 04:02:23 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
|
|
|
|