Hacker Read top | best | new | newcomments | leaders | about | bookmarklet login

This is an active area of work; check out the docs for "experimental commands" at https://nixos.org/manual/nix/unstable/command-ref/new-cli/ni..., especially `nix profile` and `nix search`, where your examples would become:

    nix profile install nixpkgs#package_name

    nix search nixpkgs keyword


sort by: page size:

I think it's basically just the man pages online, but I've found this resource to be pretty helpful:

https://nixos.org/manual/nix/stable/command-ref/new-cli/nix....


The docs could be better, but it's as easy as:

1. Install Nix from https://nixos.org/download.html

2. Find the package from https://search.nixos.org/packages

3. Start a shell with `nix-shell -p <name>`, have the package available in it


For installing a package, you have to specify the package repository. For uninstalling, you don't because you're operating against a separate repository containing locally installed packages. This should be the same for the new CLI too.

Looking at the manual[1], instead of:

    nix profile remove nixpkgs#ripgrep
You'd probably need to run:

    nix profile remove packages.x86_64-linux.ripgrep
For searching packages,

    nix search nixpkgs ripgrep
is faster than

    nix-env -qaP ripgrep
But I find the online search UI[2] to be far more superior.

[1]: https://nixos.org/manual/nix/unstable/command-ref/new-cli/ni...

[2]: https://search.nixos.org/packages


I considered something similar. No experience myself, but the starting points would be here:

http://releases.nixos.org/nix/nix-1.7/manual/#chap-writing-n...

http://nixos.org/nixpkgs/manual/

Looks alien to me (of course, it's new!), but not too scary. Might give it a spin in a VM at least.


I think nix already does what you want for search, but the install suggestion is a good idea.

`nix install packagename` would fall outside the current command convention (since `profile` is a command and `install` is a subcommand of profile), so they would have to introduce a new top-level command "install" which is aliased to `profile install`. Given the `nix` command itself is a newer/experimental alternative to `nix-env`, et al., in a seemingly similar spirit to `apt-get/apt-cache` -vs- `apt`, I think creating such an alias would be a very reasonable thing to do.

`nix search packagename` afaik currently does what you (probably) want. It defaults to searching in both `packages.<system>` & `legacyPackages.<system>`, so nixpkgs will be included. I suspect the inclusion of `nixpkgs` in the examples above is actually narrowing the search, possibly for speed: doing `nix search packagename` is currently a bit slow.


In case anyone overlooks it, search.nixos.org also will link to the nix code in nixpkgs for a package.

With flakes, IIRC, `nix edit nixpkgs#<pkg>` will also open up the source. https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3...



nix-env is a little worse than your examples suggest. It's really:

    nix-env -iA nixpkgs.package_name
Can't forget the leading `nixpkgs.`. And searching is:

    nix-env -qaP '.*keyword.*'
Because `--query` takes a regex -- unlike all of the other nix-env subcommands, which take globs.

But `nix search` has been available for years, and works great.

There's still no nice interface for installing packages, but that's not actually an operation you do very often with Nix, since you're mostly specifying environments in files, rather than mutating your own user environment. Of course, newcomers don't know that, and they want to manipulate things in their PATH like every other package manager, so that's not an excuse for the bad ergonomics. The upcoming version of Nix adds `nix profile install` which is a bit more intuitive.

I think Nix's current CLI makes git look positively humane, but I'm encouraged that it's been steadily improving.


Where are the docs for the nix command?

It does slowly happen. There's a new `nix` command (a.k.a. Nix 2.0), which has a better CLI, though it's not yet 100% complete, I believe. But already useful (e.g. `nix search`).

https://nixos.org/nix/manual/#ssec-relnotes-2.0


I think https://nix.dev is what you are looking for. It's a really great resource (and no need to go all in and do _everything_ in nix)

I learned about this very recently[1] and it seems like an amazing use case that I wish got more play in the marketing of Nix. I have a lot of dumb "productivity" scripts that I wrote at work (Linux) that I can't run at home (macOS) because of differences in the behavior of `find` or `date` whatever. I plan on porting them to use `nixpkgs.findutils` etc. and never having to worry about this again.

[1]: https://ianthehenry.com/posts/how-to-learn-nix/command-refer...


Nix search package-name does work actually. These are the older CLI tools and there is WIP for a newer interface.

Nix 3 has a dead simple, builtin CLI frontend for doing this with built packages: https://nixos.org/manual/nix/unstable/command-ref/new-cli/ni...

It uses dockerTools: https://github.com/NixOS/bundlers/blob/master/flake.nix

maybe a bundler can be added that uses OCI tools, thus providing such a wrapper and giving a nice CLI for it



Thanks. I also found this Cheatsheet from the NixOS Wiki with comparisons to apt-get to be useful: https://nixos.wiki/index.php?title=Cheatsheet&useskin=vector

I would also love to see a tutorial for beginners on Linux that covers common tasks like viewing changelogs, creating a simple package, and pinning multiple dependencies in an environment.


1. How common is it to search outside nixpkgs?

2. How common is it to install from outside nixpkgs?

Depending on the answers to the above:

`nix install packagename` should default to nixpkgs and install into currently active profile (if auch a thing as currently active profile is a thing in nix, of course)

`nix search packagename` should default to searching nixpkgs

Boom. You improved developer/user experience 100-fold with little effort.

Edit: 99.9% of examples in the linked page have nixpkgs# prefix for packages. Just drop it, and make it default. Everyone will thank you.


Yes!

    # search for a package called `foo`
    nix search nixpkgs foo
    # install package foo, user-wide
    nix-env -i foo
The CLI UX can get better, and I'm fairly sure folks are working on it.

You can also test-drive a package without committing to it, e.g. you want to try the program `cowsay` but only want to use it once:

    nix-shell -p cowsay
    cowsay
    exit
This spawns a new shell with `cowsay` available, and after you exit it won't be cluttering your system packages.

Cheers. Yeah for sure, I was too lazy to make a PR on nixpkgs, but this[0] is what I wrote if anyone stumbles on this using NixOS. The nix package manager can be installed on top of most OS's too.

[0]: https://pastebin.com/raw/FYMean1q

next

Legal | privacy