Skip to content

Instantly share code, notes, and snippets.

@AleXoundOS
Forked from LnL7/find-fixed-outputs.nix
Last active September 27, 2019 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AleXoundOS/b9a535bad5ff5a2a44f21774cfd772e8 to your computer and use it in GitHub Desktop.
Save AleXoundOS/b9a535bad5ff5a2a44f21774cfd772e8 to your computer and use it in GitHub Desktop.
Find fixed output derivations
# Copyright (c) 2003-2019 Eelco Dolstra, Daiderd Jordan, Alexander Tomokhov and
# the Nixpkgs/NixOS contributors.
#
# This work is licensed under the terms of the MIT license.
# For a copy, see <https://opensource.org/licenses/MIT>.
#
# This expression returns a list of all fixed output derivations used by ‘expr’.
# eg.
# $ nix-instantiate find-fixed-outputs.nix --eval --strict --json --arg expr '(import <nixpkgs> {}).hello'
with import ../.. { };
with lib;
{ expr }:
let
root = expr;
uniqueSrcs = map (x: x.file) (genericClosure {
startSet = map (file: { key = file.hash; inherit file; }) srcs;
operator = const [ ];
});
srcs = map (drv: { urls = drv.urls or [drv.url or ""];
drv = drv.drvPath;
hash = drv.outputHash;
type = drv.outputHashAlgo;
mode = drv.outputHashMode;
name = drv.name;
path = drv;
}) drvDependencies;
drvDependencies =
filter
(drv: drv.outputHash or "" != "")
dependencies;
dependencies = map (x: x.value) (genericClosure {
startSet = map keyDrv (derivationsIn' root);
operator = { key, value }: map keyDrv (immediateDependenciesOf value);
});
derivationsIn' = x:
if !canEval x then []
else if isDerivation x then optional (canEval x.drvPath) x
else if isList x then concatLists (map derivationsIn' x)
else if isAttrs x then concatLists (mapAttrsToList (n: v: addErrorContext "while finding fixed outputs in '${n}':" (derivationsIn' v)) x)
else [ ];
keyDrv = drv: if canEval drv.drvPath then { key = drv.drvPath; value = drv; } else { };
immediateDependenciesOf = drv:
concatLists (mapAttrsToList (n: v: derivationsIn v) (removeAttrs drv ["meta" "passthru"]));
derivationsIn = x:
if !canEval x then []
else if isDerivation x then optional (canEval x.drvPath) x
else if isList x then concatLists (map derivationsIn x)
else [ ];
canEval = val: (builtins.tryEval val).success;
in uniqueSrcs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment