# NixOS

Befehle

Apps suchen unter [https://search.nixos.org/packages](https://search.nixos.org/packages)

<table border="1" id="bkmrk-nix-shell--p-bitward" style="border-collapse: collapse; width: 99.9058%;"><colgroup><col style="width: 50.0472%;"></col><col style="width: 50.0472%;"></col></colgroup><tbody><tr><td>nix-shell -p bitwarden</td><td>zum installieren von Bitwarden </td></tr><tr><td>nix-env --install bitwarden</td><td>installiert Bitwarden im System permanent</td></tr><tr><td>sudo nixos-rebuild switch --upgrade</td><td>Update des Systems</td></tr><tr><td>sudo nixos-rebuild switch --rollback</td><td>Vorherigen Stand wiederherstellen.</td></tr></tbody></table>

## Programme Dauerhaft installieren

```
sudo nano /etc/nixos/configuration.nix
```

Füge das Programm hinzu

```bash
environment.systemPackages = with pkgs; {
  htop 
  # andere Pakete hier hinzufügen
}
```

Aktualisiere die NixOs-Konfiguration

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

## Nix Konfiguration im Homeordner

```
mkdir ~/nixos
sudo cp -r /etc/nixos/* ~/nixos/
```

kopiert die einstellungen in den Homeordner. Der kann leichter gesichert werden.

Git erstellen

```
cd ~/nixos
git init
git add .
git commit -m "Erster Stand"
```

### 2. Online-Repo erstellen (GitHub, GitLab, Gitea, Codeberg …)

### 3. Verknüpfen:

```
git remote add origin <URL>
git push -u origin main
```

Ab jetzt sicherst du Änderungen mit:

```
git add .
git commit -m "Update"
git push
```

#### ⭐ **Weg 2: Backup auf USB-Stick**

```
git clone ~/nixos /media/usb/nixos-backup
```

#### ⭐ **Weg 3: Backup in einer Cloud (OneDrive, Dropbox, Nextcloud)**

Den ganzen Ordner `~/nixos` einfach in einen Sync‑Ordner legen:

```
mv ~/nixos ~/OneDrive/nixos

```

→ Git + Cloud = doppelte Sicherheit.

#### 🔁 **Wie stelle ich das System später wieder her?**

Neue Maschine? Festplatte neu?

Du installierst NixOS minimal und machst danach:

```
git clone <repo-url> ~/nixos
cd ~/nixos
sudo nixos-rebuild switch --flake .

```

💥 **Boom — dein ganzes System ist zurück.**

#### 🛡️ **Was passiert mit deinen eigenen Skripten?**

Wenn du deine eigenen Skripte in dein Git‑Repo legst, z. B.:

```
~/nixos/scripts/meinskript.sh

```

und in der Nix‑Konfiguration referenzierst:

<div id="bkmrk-werden-sie-im-repo-v" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">- werden sie **im Repo versioniert**
- beim Rebuild **in den Nix Store kopiert**
- bei Neuinstallation **automatisch wiederhergestellt**

</div>**Damit ist das Problem „/home/hermann/bin existiert nicht“ sauber gelöst.**

Du kannst deinen Konfigurationsordner z. B. so anlegen:

```
~/Nextcloud/nixos/
```

Und dann:

```
cd ~/Nextcloud/nixos
git init
git add .
git commit -m "Initial commit"
```

### ✔️ **Wiederherstellung extrem einfach**

Neue Maschine oder Neuinstallation?

```
cd ~/Nextcloud/nixos
sudo nixos-rebuild switch --flake .
```

#### ⭐ **Git + Nextcloud = doppelte Sicherheit**

Der beste Setup ist:

<div id="bkmrk-ordner-in-nextcloud%3A" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">1. Ordner in Nextcloud:
    
    ```
    ~/Nextcloud/nixos
    
    ```
2. Git‑Repo in diesem Ordner:
    
    ```
    cd ~/Nextcloud/nixos
    git init
    
    ```

</div>#### ⭐ Wichtiges Detail:

Du solltest den Ordner nicht gleichzeitig in `/etc/nixos` haben

Stattdessen:

<div id="bkmrk-arbeite-und-speicher" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">1. **Arbeite und speichere in:**
    
    ```
    ~/Nextcloud/nixos
    
    ```
2. **Und verknüpfe `/etc/nixos` mit deinem Ordner**

</div>z. B. via Symlink:

```
sudo rm -r /etc/nixos
sudo ln -s ~/Nextcloud/nixos /etc/nixos

```

Dann ist `/etc/nixos` nur ein Zeiger – und du bearbeitest alles dort, wo Nextcloud es sichert.

## Nixpaket selber machen 

```
{ stdenv }:

stdenv.mkDerivation {
  name = "hello";
  src = ./hello.sh;
  installPhase = ''
    mkdir -p $out/bin
    cp $src $out/bin/hello
  '';
}
```

Ein Skript selber einbinden über Flake

```
environment.systemPackages = [ self.packages.${system}.meinProgramm ];
```

## Flakes

```
{
  description = "Meine NixOS-Konfiguration";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
  };

  outputs = { self, nixpkgs }: {
    packages.x86_64-linux.defaultPackage = 
      nixpkgs.legacyPackages.x86_64-linux.hello;
  };
}
```

### Konfiguration von einstellungen

über den Home-Manger

```

programs.bash.enable = true;

programs.bash.shellAliases = {
  ll = "ls -la";
};

programs.bash.initExtra = ''
  export EDITOR=nvim
'';

```

Ja, Hermann — **du kannst die Fish‑Shell absolut mit Home Manager verwenden** und das funktioniert sogar **sehr komfortabel**, viel besser als manuelles Dotfile‑Gebastel.

Ich zeige dir genau:

<div id="bkmrk-%E2%9C%94%EF%B8%8F-ob-es-geht-%28ja%29-%E2%9C%94" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">- ✔️ ob es geht (JA)
- ✔️ wie du Fish aktivierst
- ✔️ wie du deine eigene Konfiguration einbringst
- ✔️ wie du Plugins und Aliases verwaltest
- ✔️ warum Home Manager das perfekt unterstützt

---

</div># ⭐ **Ja, Home Manager unterstützt die Fish‑Shell vollständig**

Home Manager hat ein eigenes Modul:

programs.fish.enable = true;

Damit erzeugt Home Manager automatisch:

<div id="bkmrk-deine-config.fish-de" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">- deine `config.fish`
- dein Fish‑Init‑Skript
- deine Aliases
- deine Funktionen
- deine Plugins (über `oh-my-fish` oder Fisher)

</div>Du musst nicht mehr manuell in `~/.config/fish/config.fish` arbeiten.

<div id="bkmrk-" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># 🧩 **Beispiel: Fish in Home Manager aktivieren**

In deiner Home‑Manager‑Config (z. B. `home/hermann.nix`):

```
programs.fish = {
  enable = true;
  interactiveShellInit = ''
    echo "Hallo Herrmann, Welcome to Fish!"
  '';
  shellAliases = {
    ll = "ls -alh";
    gs = "git status";
  };
};
```

Damit erledigt Home Manager:

<div id="bkmrk-shell-aktivieren-kon" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">- Shell aktivieren
- Konfiguration erzeugen
- Aliases setzen
- Init‑Code einfügen

---

</div># ⭐ **Fish als Standardshell setzen**

Zusätzlich in NixOS selbst:

users.users.hermann.shell = pkgs.fish;

Dann ist Fish auch beim Login (TTY oder GUI) aktiv.

<div id="bkmrk--1" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># 🎣 **Fish Plugins einbinden**

Du kannst direkt Plugins definieren:

<div id="bkmrk-programs.fish.plugin" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;"><div class="">programs.fish.plugins = [</div><div class=""> {</div><div class=""> name = "fzf-fish";</div><div class=""> src = pkgs.fzf-fish;</div><div class=""> }</div><div class="">];</div></div>Oder mit Fisher:

<div id="bkmrk-programs.fish.fisher" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;"><div class="">programs.fish.fisherPlugins = [</div><div class=""> "jorgebucaran/fisher"</div><div class=""> "jethrokuan/z"</div><div class=""> "PatrickF1/fzf.fish"</div><div class="">];</div></div>Home Manager installiert alles sauber und reproduzierbar.

<div id="bkmrk--2" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># ⭐ **Eigene Konfiguration einfügen**

Wenn du eigene Fish‑Funktionen oder eigene Konfigdateien hast:

**Variante A — Inline-Konfiguration:**

<div id="bkmrk-programs.fish.intera" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;"><div class="">programs.fish.interactiveShellInit = ''</div><div class=""> set -g EDITOR nvim</div><div class="">'';</div></div>**Variante B — ganze Dateien einbinden:**

<div id="bkmrk-home.file.%22.config%2Ff" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;"><div class="">home.file.".config/fish/functions/myfun.fish".source = ./functions/myfun.fish;</div><div class="">``</div></div>Home Manager legt diese Dateien automatisch an.

<div id="bkmrk--3" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># ⭐ **Warum Fish + Home Manager so gut zusammenpassen**

<div id="bkmrk-keine-dotfiles-mehr-" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">- Keine Dotfiles mehr kopieren
- Keine Konflikte mehr
- Identische Shell überall (Laptop, PC, Server)
- Rollbacks funktionieren
- Plugins sauber versioniert
- Backups über Git + Nextcloud automatisch gesichert

</div>Viele NixOS‑User nutzen Fish **genau wegen Home Manager**, weil das Zusammenspiel perfekt ist.

<div id="bkmrk--4" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># ❗ **Wichtiger Hinweis**

Wenn Home Manager aktiv ist, solltest du **niemals** die Datei:

```
~/.config/fish/config.fish

```

manuell bearbeiten.

Home Manager überschreibt sie bei jedem „Rebuild“.  
Alle Änderungen gehören in die Home‑Manager‑Config.

<div id="bkmrk--5" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># ❓ Kontrollfrage

Wenn du Fish über Home Manager aktivierst — **wo sollten deine Aliases, Plugins und Konfigurationen gespeichert werden?**

a) Direkt in `~/.config/fish/config.fish`  
b) In der Home‑Manager‑Konfiguration (`home/hermann.nix`)  
c) In `/etc/nixos/configuration.nix`  
d) In `/home/hermann/bin`

Welcher Buchstabe ist richtig?

Alles klar, Hermann — ich gebe dir jetzt die **sauberste, stabilste und wirklich praxistaugliche Best‑Practice‑Methode**, um ein vollständig funktionierendes NixOS‑System **auf einem neuen Rechner oder nach einer Neuinstallation** wiederherzustellen.

Du bekommst:

<div id="bkmrk-den-genauen-ablauf%2C-" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">- **den genauen Ablauf**, Schritt für Schritt
- **was du vorher sichern musst**
- **was NixOS rekonstruiert**
- **wie du Nextcloud + Git effektiv nutzt**
- **den exakten Wiederherstellungsprozess** (minimal, klar, idiotensicher)

</div>Das ist die Methode, die 99 % der erfahrenen NixOS‑User nutzen.

<div id="bkmrk--7" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># ⭐ **Best Practice: Ein neues NixOS wiederherstellen, wenn die Konfiguration in Nextcloud liegt**

## 📌 **Vorher (auf deinem Hauptsystem): Was du in Nextcloud brauchst**

In `~/Nextcloud/nixos` liegt idealerweise:

```
nixos/
  flake.nix
  flake.lock
  nixos/
    configuration.nix
    hardware-configuration.nix
  home/
    hermann.nix
  scripts/
    eigene Skripte
  modules/
    optionale Module

```

UND:  
Das Ganze als **Git‑Repository**, damit du Versionen hast.

<div id="bkmrk--8" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># ⭐ **Schritt‑für‑Schritt Wiederherstellung auf einem frisch installierten NixOS**

## 🟦 **Schritt 0 – Minimal NixOS installieren (ohne Konfiguration)**

Während der grafische Installer fragt:

<div id="bkmrk-partitionierung-%E2%86%92-eg" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">- Partitionierung → egal
- User erstellen → ja
- Desktop → egal
- Konfiguration erzeugen lassen → JA (wegen hardware‑configuration.nix)

</div>Nach der Installation hast du ein absolut minimales Grundsystem.

<div id="bkmrk--9" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># 🟦 **Schritt 1 – Bei deiner Nextcloud anmelden**

Nach dem ersten Boot:

<div id="bkmrk-starte-dein-system-m" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">1. Starte dein System
2. Melde dich in Nextcloud an
3. Warte, bis der Ordner `~/Nextcloud/nixos` synchronisiert ist

</div>> **Du brauchst KEINE NixOS‑Konfig im System — die kommt jetzt komplett aus Nextcloud.**

<div id="bkmrk--10" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># 🟦 **Schritt 2 – /etc/nixos durch deine Nextcloud-Version ersetzen**

### 1. Alte config entfernen:

sudo rm -rf /etc/nixos

### 2. Symlink auf deine Nextcloud‑Konfig setzen:

sudo ln -s ~/Nextcloud/nixos /etc/nixos

Ab jetzt ist `/etc/nixos` nur noch ein Zeiger auf deine Nextcloud‑Config.

<div id="bkmrk--11" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># 🟦 **Schritt 3 – NixOS rebuild**

Wenn du Flakes nutzt (empfohlen):

sudo nixos-rebuild switch --flake /etc/nixos

UND DU BIST FERTIG.

💥 **Dein komplettes System ist wiederhergestellt.**

Was wird automatisch gesetzt?

<div id="bkmrk-alle-systempakete-al" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">- alle Systempakete
- alle Dienste
- alle Netzwerkeinstellungen
- alle Nutzer
- deine Shell (z. B. Fish)
- deine Home‑Manager‑Konfiguration
- deine Fonts
- deine Window‑Manager‑ oder Desktop‑Konfiguration
- deine Skripte (wenn sie als Pakete eingebunden sind)
- deine Dotfiles (generiert von Home Manager)
- etc.

</div>Alles, was DU definiert hast.

<div id="bkmrk--12" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># ⭐ **Was wird NICHT automatisch wiederhergestellt?**

Nur:

<div id="bkmrk-private-dateien-%28%7E%2Fd" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">- private Dateien (`~/Documents`, `~/Pictures`, etc.)
- Downloads
- Medien
- zufällige Dateien im Home‑Verzeichnis

</div>Aber die liegen **in deiner Nextcloud**, also sind sie sowieso wieder da.

Der Rest ist komplett durch NixOS und Home Manager reproduziert.

<div id="bkmrk--13" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># 🟦 **Schritt 4 – Fertig. Wirklich.**

Kein Rumkopieren.  
Kein händisches Nachkonfigurieren.  
Keine Dotfiles anpassen.  
Keine Programme neu installieren.  
Kein Chaos.

<div id="bkmrk--14" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># ⭐ **Warum ist diese Methode „Best Practice“?**

Weil:

<div id="bkmrk-nextcloud-deine-date" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">- **Nextcloud** deine Daten sichert
- **Git** deine komplette Versionierung speichert
- **NixOS** dein System reproduzierbar macht
- **Home Manager** dein Home reproduzierbar macht
- **Flakes** alles sauber einfrieren

</div>Diese Kombination ist:

👉 **das stabilste Desktop‑Setup, das du in Linux bekommen kannst**  
👉 **komplett unzerstörbar**  
👉 **100 % portabel auf jeden Rechner**

<div id="bkmrk--15" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># 🧠 **Beispiel: Neuinstallation in der Praxis**

<div id="bkmrk-neuer-pc-nixos-minim" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">- Neuer PC
- NixOS minimal installieren (egal wie)
- Nextcloud anmelden
- Warten bis `~/Nextcloud/nixos` synchronisiert ist
- Symlink setzen
- Rebuild
- Fertig

</div>Dauer: **5–10 Minuten**.  
Dein ganzes System ist identisch wie vorher.

<div id="bkmrk--16" style="font-family: 'Segoe UI'; font-size: 14px; font-style: normal; font-weight: 400; line-height: 20px;">---

</div># ❓ Kontrollfrage

Warum setzt man auf einem neuen NixOS nach der Installation **einen Symlink** von:

```
/etc/nixos → ~/Nextcloud/nixos

```

statt die Dateien einfach zu kopieren?

(Ein Satz reicht.)