dustinlyons / nixos-config

General purpose Nix configuration for macOS / NixOS with starter templates + step-by-step guides ✨
BSD 3-Clause "New" or "Revised" License
1.8k stars 113 forks source link

error: selector 'bash' matches no derivations #45

Closed karelbilek closed 10 months ago

karelbilek commented 10 months ago

I am absolute noob with Nix.

I am following your tutorial. I am stuck at step 6

"6. Decide what packages to install"

Well, I decided to install Bash. I do nix-env -i bash, I get

error: selector 'bash' matches no derivations

What should I do? All the tutorials I can find always assume I understand Nix :D

karelbilek commented 10 months ago

Also what does it mean

Review these files

darwin/casks ...

There are no files anywhere named like that?

dustinlyons commented 10 months ago

No worries! We were all Nix noobs at one time ;)

So on step 6, it just means you go to those files and add the packages you want. For example, I keep a bunch of stuff here:

https://github.com/dustinlyons/nixos-config/blob/main/modules/shared/packages.nix

Then when you run nixos-rebuild switch later, all those packages get installed.

You should review each file in the list from Step 6.

Finally, check this website to understand what packages are available:

https://search.nixos.org/packages

Sidenote, nix-env -i bash is an "imperative" way of installing packages. Now, with Nix, you'll just define a bunch of packages in a file and then Nix makes it so. This makes Nix "declarative", i.e describe what you want instead of running commands.

dustinlyons commented 10 months ago

I most always define what I want in my configuration and then let Nix install everything. But if I want to do something one-off, I run this command:

nix shell nixpkgs#<package name>

instead of nix-env.

If you see a dash in a command, that's the "legacy" way of doing Nix. If you see a space, like nix shell, that's using the latest experimental commands which will eventually become the standard way.

So I generally avoid anything with a - in it. I know, confusing.

https://nixos.org/manual/nix/stable/command-ref/experimental-commands

karelbilek commented 10 months ago

Ahhhh... ok... I guess? :D

After I did [ -f /etc/nix/nix.conf ] && sudo mv /etc/nix/nix.conf /etc/nix/nix.conf.before-nix-darwin

I cannot do

nix run .#build

anymore, I get

error: experimental Nix feature 'nix-command' is disabled; add '--extra-experimental-features nix-command' to enable it

Should I move it back?

So sorry for all the questions

dustinlyons commented 10 months ago

Just fixed the README in Step 6, you're right that was confusing. Those paths were before I did a big refactor.

Run

nix run .#build --extra-experimental-features nix-command

dustinlyons commented 10 months ago

Actually, pull the latest and try again. It was a bug in my command.

dustinlyons commented 10 months ago

Erg.. hold on. You probably used a template. I just fixed the apps/build and apps/build-switch command to use --extra-experimental-features instead of --experimental-features.

dustinlyons commented 10 months ago

You may have to do that in your local given your template won't update with the latest.

dustinlyons commented 10 months ago

Just fixed the templates as well, but you'd have to start over by initializing the template again. Or you can just fix the script like this:

https://github.com/dustinlyons/nixos-config/commit/073fac3baaccbedfa4de4c196f611f1e0d27b4f0

karelbilek commented 10 months ago

Thanks, now I am a bit confused what to do but will try :D

dustinlyons commented 10 months ago

Sorry, you're getting my responses in real time 😆

You can just grab the latest template and try again, I fixed it in the script.

Or edit the file at apps/build and apps/build-switch in your local environment to change --experimental-features to --extra-experimental-features.

Either will work.

karelbilek commented 10 months ago

No problem.

I.. don't have templates folder.

I just removed ~/nixos-config and started from zero. :) Hopefully.

karelbilek commented 10 months ago

Now I get

error: experimental Nix feature 'nix-command' is disabled; add '--extra-experimental-features nix-command' to enable it
karelbilek commented 10 months ago

I will try to nuke everything and start again

karelbilek commented 10 months ago

I got the same error.

See asciinema recording.

https://asciinema.org/a/jTfmol4P5z12bEppIOgPUNeaC (note, will get deleted in 7 days)

I will try to randomly put --extra-experimental-features nix-command to random places and see what fixes it

karelbilek commented 10 months ago

Why is the sudo mv /etc/nix/nix.conf /etc/nix/nix.conf.before-nix-darwin thing necessary? I think not doing it fixes things.

karelbilek commented 10 months ago

(and last question, should I be using these "experimental features"? According to nix manual, "Experimental features are considered unstable, which means that they can be changed or removed at any time")

dustinlyons commented 10 months ago

sudo mv /etc/nix/nix.conf /etc/nix/nix.conf.before-nix-darwin may not be necessary, I had a warning at one point about it but that may have gone away.

So the Nix community moves Nix forward, but they do so under 'experimental features'. They're just saying the APIs could change on you, so don't write production code on it. But the community has vastly moved on to Nix flakes, Nix commands, etc, instead of Nix channels, nix-env. It's just how the community iterates and adds new features to Nix and NixOS.

Eventually, stuff from experimental features will be stable and be part of the core.

dustinlyons commented 10 months ago

I wouldn't advise trying to throw --extra-experimental-features nix-command on random places :)

It just needs to be here

https://github.com/dustinlyons/nixos-config/blob/main/apps/aarch64-darwin/build https://github.com/dustinlyons/nixos-config/blob/main/apps/aarch64-darwin/build-switch

Make sure that doesn't say --experimental-features but instead it should say --extra-experimental-features.

karelbilek commented 10 months ago

I see that this whole repo is doing too many things at once, which is probably not for me. I try to understand 1/100 of it but it's too much. i guess it's not for newcomers to nix. Closing this issue, sorry

dustinlyons commented 10 months ago

Sorry this didn't work out for you. You may want to start with a few beginner-focused resources, and then once you get a grasp of the main concepts, try building your own configuration using this project as a reference.

Beginner focused resources:

Best of luck!