-
Notifications
You must be signed in to change notification settings - Fork 1
/
nixos.html
302 lines (291 loc) · 12 KB
/
nixos.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<!--
8"""8 8"""" 8"""8 8""""8 8""""8 8 8 8""""8 8""""
8 8 8 8 8 8 8 8 8 8 8 8 8 8
8e 8 8eeee 8eee8e 8e 8 8eeee8ee 8e 8 8e 8 8eeee
88 8 88 88 8 88 8 88 8 88 8 88 8 88
88 8 88 88 8 88 8 88 8 88 8 88 8 88
88 8 88eee 88 8 88eee8 88eeeee8 88ee8 88eee8 88eee
[website] https://www.nerdbude.com
[mail] [email protected]
[twitter] @PH_0x17
[github] https://www.github.com/nerdbude
-->
<!DOCTYPE html>
<html>
<head>
<title>NERDBUDE</title>
<meta charset="utf-8" />
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@PH_0x17">
<meta property="og:url" content="https://www.nerdbude.com/nixos.html">
<meta property="og:title" content="NixOS">
<meta property="og:description" content="Nach 15 Jahren Debian wird es mal Zeit für etwas neues, nämlich NixOS. Noch nie hab ich ein OS so geliebt und gehasst.">
<meta property="og:image" content="https://www.nerdbude.com/images/fav.png">
<link rel="icon" type="image/png" href="https://www.nerdbude.com/images/fav.png">
<link rel="alternate" href="https://nerdbude.com/rss/rss.xml" type="application/rss+xml" title="NERDBUDE"/>
<link rel="stylesheet" type="text/css" href="css/style.css" media="screen">
</head>
<body>
<!--- HEADER -->
<header>
<div id="headerimage">
<h1 id="terminal"><a href="https://www.nerdbude.com" class="front">NERDBUDE</a></h1>
<h3>[ code. keyboards. terminals. cyber. ]</h3>
<table>
<tr>
<th><a href="https://www.nerdbude.com/readme.html" class="front">[HOWTO]</a></th>
<th><a href="https://www.nerdbude.com/about.html" class="front">[WHOAMI]</a></th>
<th><a href="https://www.nerdbude.com/podcast/index.html" class="front">[PODCAST]</a></th>
<th><a href="https://www.nerdbude.com/frankenswitches.html" class="front">[FRANKENSWITCHES]</a></th>
<th><a href="https://www.nerdbude.com/en/en_nixos.html" class="front">[ENGLISH]</a></th>
</tr>
</table>
</div>
</header>
<div id="content">
<!-- ARTIKLE START -->
<h2>NixOS</h2>
<time>2021-04-06</time><br><br>
Seit nun mehr 15 Jahren (shit bin ich alt) bin ich treuer Debian User.<br>
Wer sein System schon mal neu aufsetzen musste und das hab ich in den 15 Jahren doch das ein oder andere Mal machen müssen, der weiß wie nervig es sein kann sein System wieder auf den Stand zu bringen wie davor.<br>
Filebackups ist das eine, das System selber ist aber ein anderes Blatt.<br>
Da aus Neugier öfter mal was neues ausprobiert werden muss kam also NixOS ins Spiel.<br>
Ursprünglich stand Arch Linux zur Auswahl aber durch einen kleinen Tipp bin ich dann direkt zu NixOS gewechselt.<br>
Der Installations-Aufwand ist im Grunde ähnlich wie bei Arch-Linux, also pure Handarbeit inkl. händischer Formatierung und Partitionierung der Festplatte, und Installation des Systems von Grund auf.<br>
Die Installationsanleitung gibt es auf <a href="http://NixOS.org">https://NixOS.org</a> und ist wirklich sehr einfach und übersichtlich.<br>
<br>
Warum will man dann NixOS haben?<br>
Mittlerweile will ich ein System haben, dass so minimalistisch wie möglich daher kommt.<br>
Klar Debian kann als pure "minimalistische" Installation hergenommen werden, hat aber dennoch Pakete die übermäßig groß sind und unnötig Platz fressen.<br>
Die Pakete haben selbstverständlich unter Debian ihre Daseinsberechtigungen aber ob man die haben will ist eine andere sache.<br>
<br>
NixOS belegt ungefähr 1.5GB.<br>
Das ist ordentlich schlank und auch interessant für ältere Hardware.<br>
Als WM kommt hier natürlich auch wieder XMonad drauf. Spart auch Platz und meine Finger haben sich schon daran gewöhnt.<br>
<br>
Neben dem Vorteil der Größe ist aber noch ein anderer Punkt ausschlaggebend für meine Entscheidung.<br>
NixOS selber nennt drei Hauptvorteile: reproducible, declarativ und reliable.<br>
<br>
Reproducable: Die nix Pakete sind isoliert von einander, das stellt sicher, dass sie reproduzierbar sind und keine nicht deklarierten Dependencies hat. Funktioniert ein Paket auf einem Rechner, funktioniert es auch auf einem anderen.<br>
Declarativ: Mit NixOS kann man Entwicklungsumgebungen freigeben unabhängig davon welche Sprache oder Tools.<br>
Reliable: Durch die Installation eines Paketes werden keine anderen beschädigt. Man kann ein Rollback auf frühere Versionen durchführen und sicherstellen, dass sich während eines Upgrades kein Paket in einem inkonsistenten Zustand befindet.<br>
<br>
Im absoluten Minimum ist NixOS komplett reproducable aus einer einzigen config-file.<br>
Die magische "configuration.nix".<br>
In diesem File werden einerseits das gesamte System konfiguriert und alle nötigen Pakete, wie Sound, Wifi, WM usw. hinterlegt aber auch Programme wie Vim, Git, Python, GoAccess und alles was man braucht.<br>
Das heißt im Umkehrschluss, wenn man ein NixOS auf einem anderen Rechner installiert und die "configuration.nix" extern gebackuped hat, kopiert man sich diese auf das neue System startet einen Rebuild und hat sein bisheriges System wieder hergestellt.<br>
Einfacher geht es nicht. Kein lässtiges installieren von Hand mehr.<br>
<br>
Wenn man NixOS auf einem gleichen System wie dem Vorherigen laufen lassen möchte, gibt es auch noch die Möglichkeit sämtliche Hardwarespezifikationen in der "hardware-configuration.nix" zu hinterlegen.<br>
Würde beispielsweise mein T470 hier den Geist aufgeben und ich mir wieder ein T470 zulegen würde (kein so abwegiger Gedanke), bräuchte ich nur die "configuration.nix" und die "hardware-configuration.nix" Files und hätte innerhalb von wenigen Minuten mein System sofort wieder einsatzbereit.<br>
Das einzige was dann noch händisch drauf gepackt werden muss sind die dotfiles der einzelnen Programme.<br>
Da bin ich aber dran und das gibt dann nen separaten Blogpost.<br>
<br>
<h3>Installation</h3>
Wie installiert man NixOS:<br>
<br>
Als allererstes holt man sich die aktuelle NixOS ISO-File hier: <a href="https://nixos.org/download.html">https://nixos.org/download</a><br>
<br>
Die iso packt man sich auf einen USB-Stick oder irgendein bootfähiges Medium. (Ich hatte <a href="https://www.nerdbude.com/sd_card.html">HIER</a> mal erklärt. Ob SD-Karte oder USB Stick ist dabei egal).<br>
Danach bootet man vom Stick.<br>
Wenn alles geklappt hat, dann wird man begrüßt von einer Shell.<br>
Standartlogin ist User:nixos mit leerem Passwort.<br>
<br>
Als allererstes empfiehlt es sich das Keyboardlayout festzulegen:<br>
<br>
<span class="label">CONSOLE</span>
<div id="cssyn">
<pre>
<ln><span class="unixshell">loadkeys de de</span></ln>
</pre>
</div>
<br>
<br>
Das würde das Layout auf deutsch wechseln.<br>
<br>
Weiter gehts mit der Partitionierung der Festplatte.<br>
Das geht einmal mit UEFI und einmal mit MBR.<br>
Im Beispiel hier ist die Platte als /sda eingehängt.<br>
<br>
UEFI<br>
<br>
<span class="label">CONSOLE</span>
<div id="cssyn">
<pre>
<ln><span class="unixshell">parted /dev/sda -- mklabel gpt</span></ln>
<ln><span class="unixshell">parted /dev/sda -- mkpart primary 512MiB -8GiB</span></ln>
<ln><span class="unixshell">parted /dev/sda -- mkpart primary linux-swap -8GiB 100%</span></ln>
<ln><span class="unixshell">parted /dev/sda -- mkpart ESP fat32 1MiB 512MiB</span></ln>
<ln><span class="unixshell">parted /dev/sda -- set 3 esp on</span></ln>
</pre>
</div>
<br>
<br>
Hier werden Root und Swap Partition angelegt.<br>
<br>
<br>
MBR<br>
<br>
<span class="label">CONSOLE</span>
<div id="cssyn">
<pre>
<ln><span class="unixshell">parted /dev/sda -- mklabel msdos</span></ln>
<ln><span class="unixshell">parted /dev/sda -- mkpart primary 1MiB -8GiB</span></ln>
<ln><span class="unixshell">parted /dev/sda -- mkpart primary linux-swap -8GiB 100%</span></ln>
</pre>
</div>
<br>
<br>
Weiter gehts mit dem Filesystem.<br>
NixOS bietet verschiedene Filesysteme an.<br>
<br>
<span class="label">Ext4</span>
<div id="cssyn">
<pre>
<ln><span class="unixshell">mkfs.ext4 -L nixos /dev/sda1</span></ln>
</pre>
</div>
<br>
<br>
<span class="label">Swap</span>
<div id="cssyn">
<pre>
<ln><span class="unixshell">mkswap -L swap /dev/sda2</span></ln>
</pre>
</div>
<br>
<br>
<span class="label">FAT</span>
<div id="cssyn">
<pre>
<ln><span class="unixshell">mkfs.fat -F 32 -n boot /dev/sda3</span></ln>
</pre>
</div>
<br>
<br>
<span class="label">RAID</span>
<div id="cssyn">
<pre>
<ln><span class="unixshell">mdadm</span></ln>
</pre>
</div>
<br>
<br>
Letzter Schritt - die finale Installation.<br>
Zuerst wird das Laufwerk gemounted:<br>
<br>
<br>
<span class="label">MOUNT</span>
<div id="cssyn">
<pre>
<ln><span class="unixshell">mount /dev/disk/by-label/nixos /mnt</span></ln>
</pre>
</div>
<br>
<br>
Unter UEFI Systemen läuft das ein wenig anders ab:<br>
<br>
<br>
<span class="label">MOUNT</span>
<div id="cssyn">
<pre>
<ln><span class="unixshell">mkdir -p /mnt/boot</span></ln>
<ln><span class="unixshell">mount /dev/disk/by-label/boot /mnt/boot</span></ln>
</pre>
</div>
<br>
<br>
Wenn das alles erledigt ist, wird die vorhin erwähnte configuration.nix file angelegt.<br>
Das geht bequem per Befehl.<br>
<br>
<br>
<span class="label">CREATE CONFIG</span>
<div id="cssyn">
<pre>
<ln><span class="unixshell">nixos-generate-config --root /mnt</span></ln>
</pre>
</div>
<br>
<br>
Nun kann man entweder seine bereits vorhandene configfile hier einsetzen oder belässt die neue configfile, wenn man neu starten möchte.<br>
In jedemfall lohnt es sich die "configuration.nix" vor dem nächsten Schritt anzuschauen, da es sonst sein kann, dass NixOS nicht bootet.<br>
<br>
Der nächste Schritt ist die Installation.<br>
<br>
<br>
<span class="label">INSTALLATION</span>
<div id="cssyn">
<pre>
<ln><span class="unixshell">nixos-install</span></ln>
</pre>
</div>
<br>
<br>
Nun rattert NixOS durch bis alles nötige installiert ist. Zwischdrin wird noch ein root-passwort vergeben und wenn alles geklappt hat könnt ihr rebooten und habt ein wundervolles OS auf dem Rechner.<br>
<br>
Soweit wäre das Grundsystem fertig und weitestgehend benutzbar.<br>
<br>
<h3>Software</h3>
Nun will man aber noch 'nen WM haben, Python, Vim und und und.<br>
Es gibt zwei Möglichkeiten Programme oder Pakete zu installieren.<br>
<br>
Zum einen lassen sich Pakete lokal, in dem Sinn nur für das aktuelle System installieren:<br>
<br>
<br>
<span class="label">local</span>
<div id="cssyn">
<pre>
<ln><span class="unixshell">nix-env -iA nixos.vim</span></ln>
</pre>
</div>
<br>
<br>
Der Befehl würde Vim für den aktuellen User installieren.<br>
Das empfiehlt sich allerdings eher zum testen des Pakets, da Vim in diesem Fall nicht in der "configuration.nix" liegt und beim reproduzieren des Systems nicht mit installiert wird.<br>
Um Vim beim Transfer des Systems mit drin zu haben, muss Vim mit in die "configuration.nix".<br>
<br>
<br>
<span class="label">configuration.nix</span>
<div id="cssyn">
<pre>
<ln><span class="unixshell">environment.systemPackages = with pkgs; [</span></ln>
<ln><span class="unixshell">vim</span></ln>
<ln><span class="unixshell"> ];</span></ln>
</pre>
</div>
<br>
<br>
Dieser Eintrag muss in die "configuration.nix", damit beim Neuaufsetzen Vim mit installiert wird.<br>
Nachdem Vim im configfile eingetragen ist, muss ein rebuild ausgeführt werden.<br>
<br>
<br>
<span class="label">Rebuild</span>
<div id="cssyn">
<pre>
<ln><span class="unixshell">nixos-rebuild switch</span></ln>
</pre>
</div>
<br>
<br>
Dann hat man die, in der configuration.nix file hinterlegte config.<br>
<br>
Das sind die Grundlagen um NixOS zum laufen zu bringen, zu mindest als grundlegendes System.<br>
<br>
<br>
Über die configuration.nix file oder auch andere NixOS Themen werd ich in Zukunft noch den ein oder anderen Post raushauen.<br>
NixOS ist mit Sicherheit kein OS für jeden Menschen aber wenn man es mal hat will man es eigentlich auch nicht mehr missen.<br>
Ausprobieren lohnt sich allemale.<br>
<!-- ARTIKEL ENDE -->
<br>
<br>
<br>
<br>
<p>//EOF</p>
</div>
<!-- Footer -->
<div id="footer">
<a href="https://www.nerdbude.com/impressum.html">./impressum </a>
<a target="_blank" href="https://www.nerdbude.com/datenschutz.html">./datenschutz </a>
</div>
</body>
</html>