@@ -368,13 +368,21 @@ rec {
368368 emptyValue = { value = {}; };
369369 };
370370
371− # derivation is a reserved keyword.
371+ # A package is a top-level store path (/nix/store/hash-name). This includes:
372+ # - derivations
373+ # - more generally, attribute sets with an `outPath` or `__toString` attribute
374+ # pointing to a store path, e.g. flake inputs
375+ # - strings with context, e.g. "${pkgs.foo}" or (toString pkgs.foo)
376+ # - hardcoded store path literals (/nix/store/hash-foo) or strings without context
377+ # ("/nix/store/hash-foo"). These get a context added to them using builtins.storePath.
372378 package = mkOptionType {
373379 name = "package";
374380 check = x: isDerivation x || isStorePath x;
375381 merge = loc: defs:
376382 let res = mergeOneOption loc defs;
377− in if isDerivation res then res else toDerivation res;
383+ in if builtins.isPath res || (builtins.isString res && ! builtins.hasContext res)
384+ then toDerivation res
385+ else res;
378386 };
379387
380388 shellPackage = package // {