refactor(nix/dependency-analyzer): use unsafeDiscardOutputDependency

Turns out that pathContextDrvPath already exists as a builtin which
is very convenient. Actually somewhat embarassing that I missed this
for so long.

Change-Id: Ieb5e113d70dec548b3053911ff9dbe9ed48402be
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7050
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
sterni 2022-10-20 15:46:40 +02:00
parent b410655a5e
commit 5753fc14f5

View file

@ -7,22 +7,6 @@ let
# Utilities # Utilities
# #
# Manipulate string context of the given string so that it only carries a
# `path` reference to itself (so it needs to be a string representation of
# a store path).
#
# This is intended for use on the `drvPath` attribute of derivations which by
# default carries a reference to the corresponding outputs. If we only want to
# read from the `drvPath`, having only a `path` reference makes sure we don't
# need to realise the derivation first.
#
# Type: str -> str
pathContextDrvPath = drvPath:
let
drvPath' = unsafeDiscardStringContext drvPath;
in
appendContext drvPath' { ${drvPath'} = { path = true; }; };
# Determine all paths a derivation depends on, i.e. input derivations and # Determine all paths a derivation depends on, i.e. input derivations and
# files imported into the Nix store. # files imported into the Nix store.
# #
@ -61,7 +45,7 @@ let
# #
# Type: [drv] -> [str] # Type: [drv] -> [str]
drvsToPaths = drvs: drvsToPaths = drvs:
builtins.map (drv: pathContextDrvPath drv.drvPath) drvs; builtins.map (drv: builtins.unsafeDiscardOutputDependency drv.drvPath) drvs;
# #
# Calculate map of direct derivation dependencies # Calculate map of direct derivation dependencies
@ -78,7 +62,7 @@ let
# key may not refer to a store path, … # key may not refer to a store path, …
key = unsafeDiscardStringContext drvPath; key = unsafeDiscardStringContext drvPath;
# but we must read from the .drv file. # but we must read from the .drv file.
path = pathContextDrvPath drvPath; path = builtins.unsafeDiscardOutputDependency drvPath;
in in
{ {
inherit key; inherit key;