Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Nix: Difference between revisions

From Nest Guides
No edit summary
add nix run
Line 12: Line 12:
   
   
Once you're done, exit out using the <code>exit</code> command.
Once you're done, exit out using the <code>exit</code> command.
 
=== Run a single command ===
Sometimes, you just need a package in order to run a single command. Instead of using <code>nix shell</code>, resets your working directory, you can use <code>nix run</code> to run a command in your current environment. Use <code>nix run nixpkgs#<package></code> to run the command associated with that package. If you need to pass command line options to the command, place two dashes after the package name, such as <code>nix run nixpkgs#<package> -- <options></code>
 
=== Searching for a package ===
=== Searching for a package ===
You can also search for the package you want [https://search.nixos.org/packages online] or by running <code>nix search nixpkgs <package></code>. It appears to use a lot of memory running it from the command line so it's recommended that you use the online version instead.
You can also search for the package you want [https://search.nixos.org/packages online] or by running <code>nix search nixpkgs <package></code>. It appears to use a lot of memory running it from the command line so it's recommended that you use the online version instead.

Revision as of 02:01, 9 January 2025

This article is a stub. Please help expand it.

Nix is a package manager which is used on nest to allow users to install packages without the need of apt, which requires sudo (Superuser Do) permissions. It's normally used to make reproducible developer and production environments with just one file! What is great about nix, compared to pacman (Arch), or apt (Debian/Ubuntu), is that you can have multiple versions of a package installed on the nest server because it's on the user-level. This means one user could have Node.js 18, another 20, etc.

Nix Environment (persistent)

You can permanently install packages using nix! Just like using apt, packages will stay installed on the system even if you reboot or log off. Unlike apt, the packages are only installed for your user account, meaning sudo is not required. You can run nix profile install nixpkgs#<package> to install packages.

If you want to remove a package, you can run nix profile remove <package> The name of package will usually be the same as when you installed it (excluding the nixpkgs# part) but you can always check installed packages and their names with nix profile list

Nix shells (temporary)

Let's talk about nix shells! You can spawn a new shell with the packages so you can try out packages, and when you close out the shell, all of those packages will be gone! For example, you can run nix shell nixpkgs#<package> (replacing "package" with the packages you want) to spin up a new shell with those packages.

Once you're done, exit out using the exit command.

Run a single command

Sometimes, you just need a package in order to run a single command. Instead of using nix shell, resets your working directory, you can use nix run to run a command in your current environment. Use nix run nixpkgs#<package> to run the command associated with that package. If you need to pass command line options to the command, place two dashes after the package name, such as nix run nixpkgs#<package> -- <options>

Searching for a package

You can also search for the package you want online or by running nix search nixpkgs <package>. It appears to use a lot of memory running it from the command line so it's recommended that you use the online version instead.