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

unable to install jdk in nixos/nix docker, selector 'jdk*' matches not derivations #133786

Closed
scalavision opened this issue Aug 13, 2021 · 10 comments

Comments

@scalavision
Copy link
Contributor

scalavision commented Aug 13, 2021

Describe the bug

A clear and concise description of what the bug is.

Not able to install any jdk* version when using docker nixos

Steps To Reproduce

Steps to reproduce the behavior:

Create a docker file:

FROM nixos/nix

RUN nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs
RUN nix-channel --update

RUN nix-env --install nixpkgs.jdk8 || nix-env --install nixos.jdk8 || nix-env --install jdk8 || \
  nix-env --install nixpkgs.jdk11 || nix-env --install nixos.jdk11 || nix-env --install jdk11 || \
  nix-env --install nixpkgs.jdk16 || nix-env --install nixos.jdk16 || nix-env --install jdk16

I also tried using openjdk instead of jdk, but that did also not work.

bash:

docker build -t .

Expected behavior

A clear and concise description of what you expected to happen.

jdk should install, I tried using other packages in the same way and they
install flawlessly.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

I now you can now do program.java=enable, but that only works in NixOS right?
The use of prefix like nixpkgs, nixos has always been confusing to me, so maybe I
did something wrong in this regard?

Notify maintainers

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 5.10.57, Alpine Linux, noversion`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.3.12`
 - channels(root): `"nixpkgs-21.11pre309233.70dc433f2eb"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
 - system: `"x86_64-linux"`
 - host os: `Linux 5.10.57, Alpine Linux, noversion`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.3.12`
 - channels(root): `"nixpkgs-21.11pre309233.70dc433f2eb"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:
@GuillaumeDesforges
Copy link
Contributor

Could you provide the error message as well please?

@scalavision
Copy link
Contributor Author

scalavision commented Aug 17, 2021

sure, will this suffice?

+ nix-env -i vim
installing 'vim-8.2.2567'
these paths will be fetched (7.61 MiB download, 35.88 MiB unpacked):
  /nix/store/0dcf13hhk1kl9i0gcq7yjp8p9cp166n4-vim-8.2.2567
  /nix/store/1838raw4b33pbry9m3c4mwrfigzbkf6r-gawk-5.1.0
copying path '/nix/store/1838raw4b33pbry9m3c4mwrfigzbkf6r-gawk-5.1.0' from 'https://cache.nixos.org'...
copying path '/nix/store/0dcf13hhk1kl9i0gcq7yjp8p9cp166n4-vim-8.2.2567' from 'https://cache.nixos.org'...
building '/nix/store/ra3vm69w7x99a3mzi0phpag8ib2877xd-user-environment.drv'...
created 430 symlinks in user environment
+ nix-env -i jdk8
error: selector 'jdk8' matches no derivations
FATAL:   While performing build: while running engine: exit status 1

vim works nicely, but jdk8 fails.

@GuillaumeDesforges
Copy link
Contributor

GuillaumeDesforges commented Aug 18, 2021

error: selector 'jdk8' matches no derivations

Means it can't find a package you called jdk8.

I'd recommend having a look at https://nixos.org/manual/nix/stable/#ch-basic-package-mgmt

On NixOS:

$ nix-env -iA nixos.jdk8

on non-NixOS:

$ nix-env -iA nixpkgs.jdk8

This is not an issue with nixpkgs. You can ask for more help on any Nix beginner channel, such as Discourse. 😉

@scalavision
Copy link
Contributor Author

scalavision commented Aug 19, 2021

yes, but jdk should be available both in nixpkgs and nixos channel i think ( have tried all kinds of versions of jdk, with and without nixpkgs / nixos prefixes and different channels), so there must be something wrong with the way that name resolution works. I can't see why some of the packages are found and not this one.

Maybe the shell needs to be reinitialized as when using home-manager.

I'll try to install it directly from the git archive in the evening and see if that works :-) I'll also post a follow up on Discourse when I have time.

@peti
Copy link
Member

peti commented Aug 27, 2021

You can also use nix-env --install openjdk.

@GuillaumeDesforges
Copy link
Contributor

You can also use nix-env --install openjdk.

  • --install is short for -i previously used/suggested
  • openjdk is an alias for the "latest" jdk

https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/all-packages.nix#L11716

So I don't think this would solve the core issue.

@GuillaumeDesforges
Copy link
Contributor

From https://nixos.org/manual/nixos/stable/#sec-ad-hoc-packages

The -A flag specifies the package by its attribute name; without it, the package is installed by matching against its package name (e.g. thunderbird).

jdk8 is not the package name, while openjdk is, which makes nix-env -i openjdk work.

In general, you are better off specifying nix-env -iA nixos.jdk8 to be sure that you install what you want

@scalavision
Copy link
Contributor Author

Thanks a lot for looking into this @GuillaumeDesforges , it seems that:

nix-env -iA nixos.jdk8`

is not working for me inside the Docker container. Maybe after channel --update, the name resolution isn't properly propagated in Docker.

So I've found out that to get this to work inside Dockerfile, you need to use the -f flag, hence this works:

RUN nix-env -f '<nixpkgs>' -iA jdk8

Sadly I do nix things more occasionally these days, so a bit rusty, should of course have thought to try this as well.

@scalavision
Copy link
Contributor Author

I was sure I tested this approach earlier as well, nevertheless it works now:

nix-env -iA nixpkgs.jdk8

@GuillaumeDesforges
Copy link
Contributor

On a note: I had not seen you were not on NixOS. Maybe just nix-env -iA nixpkgs.jdk8 would do the trick

Btw if you are using dockerfile you can probably copy a Nix file with the proper package (or nix flake) and install from it, it'll relieve you of over complicated code in Dockerfile. Though this is an opinionated choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants