From 195fcd301aa31fa7014a0e775d67d0bea3c91f0c Mon Sep 17 00:00:00 2001 From: smudge <189092906+smudgebun@users.noreply.github.com> Date: Fri, 31 Jul 2026 09:50:18 -0700 Subject: [PATCH 1/2] feat: complete nix option for fetchcontent script --- .build-aux/fetchcontent2flatpak.py | 50 +++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/.build-aux/fetchcontent2flatpak.py b/.build-aux/fetchcontent2flatpak.py index 9f8f62e..fa4b747 100644 --- a/.build-aux/fetchcontent2flatpak.py +++ b/.build-aux/fetchcontent2flatpak.py @@ -149,6 +149,54 @@ def to_flatpak(sources: list[FetchContent]): return (sources_json, "\n".join(flags)) +def parse_nixout(command: list[str]) -> str: + out: str = "" + + process = subprocess.run( + command, + text=True, + bufsize=1, + capture_output=True, + ) + + if process.stdout: + out = process.stdout + return out + +def nix_fetch(url: str, rev: str, tag: str): + nix_prefetch_git = shutil.which("nix-prefetch-git") + hash: str = "FAILED" + if not nix_prefetch_git: + raise FileNotFoundError("nix-prefetch-git") + + if rev: + command = [ + nix_prefetch_git, + "--url", + url, + "--rev", + rev, + "--quiet" + ] + elif tag: + command = [ + nix_prefetch_git, + "--url", + url, + "--rev", + f"refs/tags/{tag}", + "--quiet" + ] + else: + command = [] + + print(f"nix-prefetch-git: fetching {url}") + try: + hash = json.loads(f"{parse_nixout(command)}")['hash'] + except ValueError: + print(f"nix-prefetch-git: failed to fetch {url}. re-run or fetch manually") + + return hash def to_nix(sources: list[FetchContent]): lines: list[str] = [] @@ -163,7 +211,7 @@ def to_nix(sources: list[FetchContent]): lines.append(f' tag = "{source.tag}";') elif source.commit: lines.append(f' rev = "{source.commit}";') - lines.append(' hash = "TODO";') # I don't use nix, btw + lines.append(f' hash = "{nix_fetch(f"{source.url}",f"{source.commit}",f"{source.tag}")}";') lines.append("};\n") env = ( From acfe88009eb4a55d7789c8671b923fd90a0b39f3 Mon Sep 17 00:00:00 2001 From: smudge <189092906+smudgebun@users.noreply.github.com> Date: Sun, 2 Aug 2026 17:13:58 -0700 Subject: [PATCH 2/2] feat: modify nix option to better handle edge cases --- .build-aux/fetchcontent2flatpak.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.build-aux/fetchcontent2flatpak.py b/.build-aux/fetchcontent2flatpak.py index fa4b747..b230d6b 100644 --- a/.build-aux/fetchcontent2flatpak.py +++ b/.build-aux/fetchcontent2flatpak.py @@ -176,7 +176,9 @@ def nix_fetch(url: str, rev: str, tag: str): url, "--rev", rev, - "--quiet" + "--quiet", + "--fetch-submodules", + "--no-add-path" ] elif tag: command = [ @@ -185,7 +187,9 @@ def nix_fetch(url: str, rev: str, tag: str): url, "--rev", f"refs/tags/{tag}", - "--quiet" + "--quiet", + "--fetch-submodules", + "--no-add-path" ] else: command = []