Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defaultApp should have type 'derivation' - add better error message? #6448

Open
patryk4815 opened this issue Apr 26, 2022 · 4 comments
Open
Labels

Comments

@patryk4815
Copy link

Describe the bug
Hi. Can we add better error message? I just wasted a couple of hours finding out why that doesn't work on nix 2.8.

error: attribute 'defaultApp.aarch64-linux' should have type 'derivation'

Steps To Reproduce
image

@patryk4815 patryk4815 added the bug label Apr 26, 2022
@thufschmitt
Copy link
Member

I think there’s a plain bug here (I guess a consequence of #6389): defaultApp should be an app, not a plain derivation.

That being said, what would you expect as an error message here? Agree that the current one isn’t optimal, but I’d take any input as to how it could be improved ;)

@tomberek
Copy link
Contributor

We played around with language like “Apps can only be in and must be in the apps output attribute and have type app”. It’s an if-and-only-if situation.

The other issue is the usage of defaultApp which is being deprecated and probably led to more confusion. Currently only “app.” should have apps.

@thufschmitt
Copy link
Member

thufschmitt commented May 2, 2022 via email

@wlcx
Copy link

wlcx commented May 20, 2022

For anyone searching for this error due to using nix 2.8 with a flake.nix with defaultApp, e.g. something like the below:

rec {
 # snip
 packages.my-project = naersk-lib.buildPackage {
    pname = "my-project";
    root = ./.;
  };
  defaultPackage = packages.my-project;

  # `nix run`
  apps.my-project = utils.lib.mkApp {
    drv = packages.my-project;
  };
  defaultApp = apps.my-project;
  # snip
}

(taken directly from the readme of nix-community/naersk)

You should replace defaultApp with just apps.default. Same with defaultPackage, though that seems to be more lenient with what it accepts. So, instead of the above, something like:

# snip
rec {
  packages.default = naersk-lib.buildPackage {
    pname = "my-project";
    root = ./.;
  };

  apps.default = utils.lib.mkApp { drv = packages.default;}; 
}
# snip

rowanG077 added a commit to rowanG077/cq-flake that referenced this issue May 27, 2022
rowanG077 added a commit to rowanG077/cq-flake that referenced this issue May 27, 2022
marcus7070 pushed a commit to vinszent/cq-flake that referenced this issue Jun 5, 2022
madonius pushed a commit to madonius/falsisign.nix that referenced this issue Jun 29, 2022
jjdosa added a commit to jjdosa/nix-doom-emacs that referenced this issue Aug 2, 2022
see NixOS/nix#6448 (comment)

In nix 2.8
defaultPackage and defaultApp have to be replated to
packages.default and apps.default
thenonameguy added a commit to thenonameguy/process-compose that referenced this issue Sep 10, 2022
Yay, breaking changes on minor version updates!
Cause: NixOS/nix#6448 (comment)

I'll try submitting this package to nixpkgs, so the maintanence of the
build instructions can be done separately. Until then this makes
trying out process-compose for the latest nix users a breeze.
cmars added a commit to cmars/anytype-nix that referenced this issue Jul 23, 2023
Allows `nix run .#` to work.

See NixOS/nix#6448 (comment) for
nix flake arcana.
evolutics added a commit to evolutics/travel-kit that referenced this issue Feb 4, 2024
Error message:

```
error: attribute 'defaultApp.x86_64-linux' should have type 'app'
```

Fix with help of NixOS/nix#6448.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants