[[_TOC_]]

# Nix Package Manager

## Add packages

```bash
nix-env -iA nixpkgs.<packagename>
```

If using flakes:
 
```bash
nix profile add nixpkgs#package-name
```

## Run a command

```bash
nix-shell -p hello --run "hello"
```

If using flakes:

```bash
nix shell nixpkgs#hello -c hello
```

# NixOS

## Updating a Flake based system

```bash
sudo nix update --flake /etc/nixos
sudo nixos-rebuild switch
```

## Updating a non-Flake based system

```bash
sudo nixos-rebuild switch --upgrade
```

You can use `boot` instead of `switch` for the system to boot into the new generation on reboot instead.
