Merge branch 'make-flake-show-more-lenient-on-apps' of https://github.com/flox/nix
This commit is contained in:
commit
b529a41814
|
@ -40,3 +40,7 @@
|
||||||
|
|
||||||
As before, the old output will continue to work, but `nix flake check` will
|
As before, the old output will continue to work, but `nix flake check` will
|
||||||
issue a warning about it.
|
issue a warning about it.
|
||||||
|
|
||||||
|
* `nix run` is now stricter wrt what it accepts:
|
||||||
|
* Members of `apps` are now required to be apps (as defined in [the manual](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-run.html#apps))
|
||||||
|
* Member of `packages` or `legacyPackages` cannot be of type "app" when used by `nix run`.
|
||||||
|
|
|
@ -65,6 +65,15 @@ UnresolvedApp Installable::toApp(EvalState & state)
|
||||||
|
|
||||||
auto type = cursor->getAttr("type")->getString();
|
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);
|
||||||
|
}
|
||||||
if (type == "app") {
|
if (type == "app") {
|
||||||
auto [program, context] = cursor->getAttr("program")->getStringWithContext();
|
auto [program, context] = cursor->getAttr("program")->getStringWithContext();
|
||||||
|
|
||||||
|
|
29
tests/flakes-run.sh
Normal file
29
tests/flakes-run.sh
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
source common.sh
|
||||||
|
|
||||||
|
clearStore
|
||||||
|
rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local
|
||||||
|
cp ./shell-hello.nix ./config.nix $TEST_HOME
|
||||||
|
cd $TEST_HOME
|
||||||
|
|
||||||
|
cat <<EOF > flake.nix
|
||||||
|
{
|
||||||
|
outputs = {self}: {
|
||||||
|
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 = {
|
||||||
|
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 .#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
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
nix_tests = \
|
nix_tests = \
|
||||||
flakes.sh \
|
flakes.sh \
|
||||||
|
flakes-run.sh \
|
||||||
ca/gc.sh \
|
ca/gc.sh \
|
||||||
gc.sh \
|
gc.sh \
|
||||||
remote-store.sh \
|
remote-store.sh \
|
||||||
|
|
Loading…
Reference in a new issue