Skip to content

Instantly share code, notes, and snippets.

@K900
Created September 8, 2024 11:11
Show Gist options
  • Save K900/7e4e91096163bc120ca19bd451736ac1 to your computer and use it in GitHub Desktop.
Save K900/7e4e91096163bc120ca19bd451736ac1 to your computer and use it in GitHub Desktop.
Check nixos installer for missing deps
import functools
import json
import os.path
import subprocess
import sys
@functools.lru_cache(None)
def _get_drv_info(drv):
raw = subprocess.check_output([
"nix",
"--extra-experimental-features",
"nix-command",
"derivation",
"show",
drv + "^*",
]).decode()
return json.loads(raw)[drv]
def get_output_path(drv, name):
info = _get_drv_info(drv)
return info["outputs"][name]["path"], "hash" in info["outputs"][name]
def get_inputs(drv):
info = _get_drv_info(drv)
for drv, data in info["inputDrvs"].items():
for output in data["outputs"]:
yield drv, output
@functools.lru_cache(None)
def missing_dep_chain(drv, output):
path, is_fixed = get_output_path(drv, output)
# if the path exists, we don't need to build OR fetch it
if os.path.exists(path):
return []
# if the path does not exist and is an FOD, give up immediately
if is_fixed:
return [path]
for ref in get_inputs(drv):
if chain := missing_dep_chain(*ref):
return [path] + chain
return []
def main():
for item in missing_dep_chain(sys.argv[1], "out"):
print(item)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment