This commit is contained in:
nm1 2026-11-04 00:33:23 +05:30
commit 74ae93a96e

View file

@ -0,0 +1,230 @@
basics
Absolutely — using **Nix** on Debian can give you a powerful, AUR-like experience with access to thousands of packages, isolated environments, and even rollbacks. It’s a different mindset than `apt`, but super powerful once you get the hang of it.
---
## 🧰 What Is Nix?
Nix is a **purely functional package manager**:
* Installs packages **without interfering** with your system.
* Supports **per-user installs** — no sudo needed for most things.
* Enables **isolated dev environments**, rollbacks, and reproducibility.
---
## 🧱 Step-by-Step: Installing and Using Nix on Debian
### 🔹 1. **Install Nix**
Run this script (official installer):
```bash
curl -L https://nixos.org/nix/install | sh
```
> ✅ After installation, either restart your shell or run:
```bash
. ~/.nix-profile/etc/profile.d/nix.sh
```
---
### 🔹 2. **Install a Package (like `hello`)**
```bash
nix-env -iA nixpkgs.hello
```
> This installs the `hello` program into your **user profile** — no sudo needed.
You can run it immediately:
```bash
hello
```
---
### 🔹 3. **Search for Packages**
```bash
nix search nixpkgs firefox
```
Or use the web search: [https://search.nixos.org/packages](https://search.nixos.org/packages)
---
### 🔹 4. **Upgrade Installed Packages**
```bash
nix-env --upgrade
```
---
### 🔹 5. **Remove a Package**
```bash
nix-env -e hello
```
---
## 🧪 Bonus: Reproducible Dev Environments (`shell.nix`)
Make a file named `shell.nix`:
```nix
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
buildInputs = [
pkgs.git
pkgs.nodejs
pkgs.python3
];
}
```
Then run:
```bash
nix-shell
```
This drops you into an environment with only those tools installed — perfect for development!
---
## 🔐 Is It Safe?
Yes — it’s **sandboxed**, doesn't touch your global system files, and is trusted by many in the DevOps/Dev world.
---
## ⚠️ Things to Know
* It uses a **huge store** (`/nix/store`) — so expect some disk usage.
* It can be a **learning curve**, but well worth it if you want reproducibility or project-based environments.
* You can uninstall Nix any time with `nix-env --uninstall` or delete `/nix`.
---
Want to try installing a specific package with Nix now, or explore using `home-manager` for managing your full dotfiles setup?
&nbsp;
**Installing packages**
To install **Brave** using **Nix**, you have a couple of options depending on how you want to use it (system-wide, user profile, or temporary). Here's how to do it:
---
## 🦁 Option 1: Install Brave to Your User Profile (Permanent)
First, search for it:
```bash
nix search nixpkgs brave
```
You should see a result like:
```text
brave # A privacy-focused web browser
```
Then install it:
```bash
nix-env -iA nixpkgs.brave
```
✅ This makes `brave` available permanently in your user environment.
---
## ⚡ Option 2: Use `nix shell` (Temporary)
If you just want to **run Brave without installing**:
```bash
nix shell nixpkgs#brave
```
This will drop you into a shell where `brave` is available. You can launch it:
```bash
brave
```
When you exit the shell, it's gone — no clutter!
---
## 🔥 Option 3: Use `nix run` (One-off Execution)
To run Brave **directly**:
```bash
nix run nixpkgs#brave
```
---
## 📦 Bonus: Use `home-manager` (for managing user packages declaratively)
If you're managing your dotfiles/config with Nix, you can declare Brave in your `home.nix` like this:
```nix
{
home.packages = with pkgs; [
brave
];
}
```
Then just run `home-manager switch`.
---
Would you like help setting up `home-manager` too? It's great if you're building a Nix-based setup.
&nbsp;
for enabling expermimental feature which is required for search and install packages
```sh
sudo mkdir -p /etc/nix
sudo nano /etc/nix/nix.conf
```
then add following
```txt
experimental-features = nix-command flakes
```
&nbsp;
to remove packages
if installed with nix-env
```sh
nix-env -e brave
```
and then
for removing unused packages
```sh
nix-collect-garbage
```
for older generations:
```sh
nix-collect-garbage -d
```