aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nix/app.cc15
-rw-r--r--tests/flakes-run.sh16
2 files changed, 13 insertions, 18 deletions
diff --git a/src/nix/app.cc b/src/nix/app.cc
index bd6988066..6b6b31a12 100644
--- a/src/nix/app.cc
+++ b/src/nix/app.cc
@@ -62,22 +62,17 @@ std::string resolveString(Store & store, const std::string & toResolve, const Bu
UnresolvedApp Installable::toApp(EvalState & state)
{
auto cursor = getCursor(state);
+ auto attrPath = cursor->getAttrPath();
auto type = cursor->getAttr("type")->getString();
- std::string expected;
- if (hasPrefix(attrPath,"apps.")) {
- expected = "app";
- } else {
- expected = "derivation";
- }
- if (type != expected) {
- throw Error("Attribute '%s' should have type '%s'.", attrPath, expected);
- }
+ std::string expected = !attrPath.empty() && attrPath[0] == "apps" ? "app" : "derivation";
+ if (type != expected)
+ throw Error("attribute '%s' should have type '%s'", cursor->getAttrPathStr(), expected);
+
if (type == "app") {
auto [program, context] = cursor->getAttr("program")->getStringWithContext();
-
std::vector<StorePathWithOutputs> context2;
for (auto & [path, name] : context)
context2.push_back({path, {name}});
diff --git a/tests/flakes-run.sh b/tests/flakes-run.sh
index c8035431c..88fc3e628 100644
--- a/tests/flakes-run.sh
+++ b/tests/flakes-run.sh
@@ -8,22 +8,22 @@ cd $TEST_HOME
cat <<EOF > flake.nix
{
outputs = {self}: {
- packages.$system.PkgAsPkg = (import ./shell-hello.nix).hello;
- packages.$system.AppAsApp = self.packages.$system.AppAsApp;
+ packages.$system.pkgAsPkg = (import ./shell-hello.nix).hello;
+ packages.$system.appAsApp = self.packages.$system.appAsApp;
- apps.$system.PkgAsApp = self.packages.$system.PkgAsPkg;
- apps.$system.AppAsApp = {
+ apps.$system.pkgAsApp = self.packages.$system.pkgAsPkg;
+ apps.$system.appAsApp = {
type = "app";
program = "\${(import ./shell-hello.nix).hello}/bin/hello";
};
};
}
EOF
-nix run --no-write-lock-file .#AppAsApp
-nix run --no-write-lock-file .#PkgAsPkg
+nix run --no-write-lock-file .#appAsApp
+nix run --no-write-lock-file .#pkgAsPkg
-! nix run --no-write-lock-file .#PkgAsApp || fail "'nix run' shouldn’t accept an 'app' defined under 'packages'"
-! nix run --no-write-lock-file .#AppAsPkg || fail "elements of 'apps' should be of type 'app'"
+! nix run --no-write-lock-file .#pkgAsApp || fail "'nix run' shouldn’t accept an 'app' defined under 'packages'"
+! nix run --no-write-lock-file .#appAsPkg || fail "elements of 'apps' should be of type 'app'"
clearStore