Created
November 19, 2017 21:54
-
-
Save catern/d1c4784ffe6d3314e5353b626412c517 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import json | |
import functools | |
nix_tarball_drv = "/nix/store/h0m0794x8d02hyrwkby3asajnz2s2g6n-nix-1.11.15.tar.xz.drv" | |
@functools.lru_cache() | |
def load_derivation(drv): | |
data = subprocess.check_output(['nix', 'show-derivation', drv]).decode() | |
return json.loads(data)[drv] | |
def get_drv_deps(drv): | |
data = load_derivation(drv) | |
return data['inputDrvs'].keys() | |
def is_fixed_output(drv): | |
data = load_derivation(drv) | |
try: | |
data['outputs']['out']['hash'] | |
return True | |
except KeyError: | |
return False | |
def is_substitutable_or_built(drv): | |
return subprocess.call(["nix-store", "-Q", "-j0", "--realise", drv]) == 0 | |
def needed_fixed_output_drvs(drv, already_seen=None): | |
"Outputs the unbuilt fixed-output-derivations needed to build this derivation, in topologically sorted order." | |
print(drv) | |
if already_seen is None: | |
already_seen = set() | |
if drv in already_seen: | |
return [] | |
already_seen.add(drv) | |
if is_substitutable_or_built(drv): | |
return [] | |
ret = [] | |
for dep in get_drv_deps(drv): | |
ret += needed_fixed_output_drvs(dep, already_seen) | |
if is_fixed_output(drv): | |
ret.append(drv) | |
return ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment