lib.generators: Handle no drvPath in toPretty

Previously, if a derivation without a `drvPath` was handled, an error
would be thrown:

    nix-repl> lib.generators.toPretty {} { type = "derivation"; }
    error: attribute 'drvPath' missing, at /home/infinisil/src/nixpkgs/lib/generators.nix:251:24

With this commit it doesn't anymore:

    nix-repl> lib.generators.toPretty {} { type = "derivation"; }
    "<derivation ???>"

This matches what `nix repl` outputs:

    nix-repl> { type = "derivation"; }
    «derivation ???»
launchpad/nixpkgs/master
Silvan Mosberger 3 years ago
parent 6d96191fe5
commit 307c0237d7
  1. 2
      lib/generators.nix

@ -248,7 +248,7 @@ rec {
then v.__pretty v.val
else if v == {} then "{ }"
else if v ? type && v.type == "derivation" then
"<derivation ${v.drvPath}>"
"<derivation ${v.drvPath or "???"}>"
else "{" + introSpace
+ libStr.concatStringsSep introSpace (libAttr.mapAttrsToList
(name: value:

Loading…
Cancel
Save