Nix minimal setup - kdaisho/Blog GitHub Wiki
This is a quick guide for using Nix as a package manager.
(new) deprecated -- I switched to use home-manager. No more shell.nix
. Go to the link below.
See How to install Nix home manager
sh <(curl -L https://nixos.org/nix/install) --daemon
After successful installation, run nix.
. /home/jaeger/.nix-profile/etc/profile.d/nix.sh
. /etc/profile.d/nix.sh
nix-env -iA nixpkgs.packagename
When you run nix-env -q
on Ubuntu, you'll see nix along with other installed packages (after installing nodejs and deno)
deno-2.1.9
nix-2.26.2
nodejs-22.13.1
But on Kali, you don't see nix in the list. This is actually normal behavior. It's because nix itself is not installed via nix-env
. Instead, nix is installed system-wide through the installation script, typically in /nix/store
with its binaries linked in system locations.
deno-2.1.9
nodejs-22.13.1
nix --version
This will show you the version of nix that's currently installed on your system, even though it doesn't appear in thee nix-env -q
output.
Here are some common commands to get you started:
- Search for packages:
nix search nixpkgs packagename
- Install a package:
nix-env -iA nixpkgs.packagename
- List installed packages:
nix-env -q
- Remove a package:
nix-env -e packagename
- Update all packages:
nix-env -u
I wanted to drop global level installation and have it user-level. It requires to have shell.nix
file, but this has many benefits.
nix-env -e deno
Create shell.nix
at (user) root, for example:
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = [
pkgs.deno
pkgs.nodejs_22
];
}
https://search.nixos.org/packages
nix-shell
By using a shell.nix file, you can have a centralized place where you define all the packages you're using. This gives you a single view of all your dependencies (whether it's deno, nodejs, or other tools), which can be very handy for tracking what you've installed and ensuring everything is consistent.
If you're concerned about potential conflicts with system-wide packages (installed via apt), Nix lets you manage packages in an isolated environment. This way, you don't risk messing with the global system or interfering with other software on your machine.
You can use the same shell.nix file across different systems or setups. If you need to recreate the same environment on another machine (or later down the line), you just copy over your shell.nix file, and it will bring the exact same versions of all the tools and libraries you've specified.
Even though you're using Nix for personal use, you still get the advantage of reproducibility. If you ever need to recreate your environment or share it with others (for example, another machine or project), your shell.nix file ensures that you can do that easily.
Want to know if you are in nix shell? You can dynamically modify the shell prompt.
Shell.nix for Ubuntu
Shell.nix for Kali