1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-24 03:09:35 +01:00

Make nix flake show less strict wrt what apps can be

Allow `apps.foo` and `defaultApp` to be a plain derivation like `nix run` does.

Fix #5560
This commit is contained in:
regnat 2021-11-25 14:17:25 +01:00
parent 1f7584d24c
commit 14cd643375
2 changed files with 16 additions and 7 deletions

View file

@ -1024,13 +1024,17 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
(attrPath.size() == 2 && attrPath[0] == "defaultApp") || (attrPath.size() == 2 && attrPath[0] == "defaultApp") ||
(attrPath.size() == 3 && attrPath[0] == "apps")) (attrPath.size() == 3 && attrPath[0] == "apps"))
{ {
auto aType = visitor.maybeGetAttr("type"); if (visitor.isDerivation())
if (!aType || aType->getString() != "app") showDerivation();
throw EvalError("not an app definition"); else {
if (json) { auto aType = visitor.maybeGetAttr("type");
j.emplace("type", "app"); if (!aType || aType->getString() != "app")
} else { throw EvalError("not an app definition");
logger->cout("%s: app", headerPrefix); if (json) {
j.emplace("type", "app");
} else {
logger->cout("%s: app", headerPrefix);
}
} }
} }

View file

@ -380,6 +380,11 @@ cat > $templatesDir/trivial/flake.nix <<EOF
outputs = { self, nixpkgs }: { outputs = { self, nixpkgs }: {
packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello; packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
defaultPackage.x86_64-linux = self.packages.x86_64-linux.hello; defaultPackage.x86_64-linux = self.packages.x86_64-linux.hello;
apps.x86_64-linux.helloWorld = {
type = "app";
program = "\${nixpkgs.legacyPackages.x86_64-linux.hello}/bin/hello";
};
apps.x86_64-linux.helloWorld2 = nixpkgs.legacyPackages.x86_64-linux.hello;
}; };
} }
EOF EOF