aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 26abbd07b8f81320835290593e719cddaaf37654 (plain)
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# Sources

- [Nixos manual](https://nixos.org/nixos/manual/)
- [Arch Linux installation guide](https://wiki.archlinux.org/index.php/installation_guide)
- [Installation of NixOS with encrypted root, martijnvermaat](https://gist.github.com/martijnvermaat/76f2e24d0239470dd71050358b4d5134)
- [Installing NixOS, Chris Martin](https://chris-martin.org/2015/installing-nixos)

# Prepare and boot the installation media

Download NixOS ISO at https://nixos.org/download.html.

Write ISO to a USB stick:

    ```console
    sudo dd if=nix.iso of=/dev/sdX bs=4M status=progress
    ```

Boot from the USB stick on the target machine.

Connect as sudo:

    ```console
    sudo su
    ```

# SWAP size

Check your RAM with `top`.

Get the SWAP size according to your RAM size and if you need hibernation:
https://itsfoss.com/swap-size/

# Partition the disk

Use `lsblk` your show block devices.

Launch `gdisk /dev/<disk>`:

  - verify the partition table with `v`,
  - delete every partition with `d`,
  - add a boot partition (ef00 EFI) of 500M with `n`,
  - add a system partition (8300 Linux LVM) on the remaining space with `n`,
  - write the partition table with `w`.

Encrypt your disk and open it:

    ```console
    cryptsetup luksFormat /dev/<SYSTEM>
    cryptsetup luksOpen /dev/<SYSTEM> crypted
    ```

Create swap and root logical volumes:

    ```console
    pvcreate /dev/mapper/crypted
    vgcreate vg /dev/mapper/crypted
    lvcreate -L <ram-size>G -n swap vg
    lvcreate -l '100%FREE' -n root vg
    ```

Format the partitions:

    ```console
    mkfs.fat -F 32 -n BOOT /dev/<BOOT>
    mkfs.ext4 -L nixos /dev/vg/root
    mkswap -L swap /dev/vg/swap
    ```

Mount partitions

    ```console
    mount /dev/vg/root /mnt
    mkdir /mnt/boot
    mount /dev/<BOOT> /mnt/boot
    swapon /dev/vg/swap
    ```

# Connect to Internet

Note your wifi interface:

    ```console
    ifconfig
    ```

Scan available ESSID with:

    ```console
    iwlist <INTERFACE> scan | grep ESSID
    ```

Write `wpa_supplicant` configuration:

    ```console
    wpa_passphrase <ESSID> | sudo tee /etc/wpa_supplicant.conf
    ```

Start `wpa_supplicant`:

    ```console
    wpa_supplicant -B -i <INTERFACE> -c /etc/wpa_supplicant.conf
    ```

# Install

Generate configuration:

    ```console
    nixos-generate-config --root /mnt
    ```

Rename disks by labels in `mnt/etc/nixos/hardware-configuration.nix`.

Complete `/mnt/etc/nixos/configuration.nix`

    ```nix
    # Hostname
    networking.hostName = "joris-laptop";

    # Encryption
    boot.initrd.luks.devices.root = {
      device = "/dev/disk/by-uuid/<SYSTEM>";
      preLVM = true;
      allowDiscards = true;
    };

    # Network manager
    networking.networkmanager.enable = true;

    # Enable gpg agent
    programs.gnupg.agent = {
       enable = true;
       pinentryFlavor = "tty";
       enableSSHSupport = true;
    };

    # Create user
    users.users.joris = {
      isNormalUser = true;
      extraGroups = [ "wheel" "networkmanager" ];
    };

    # Editor
    environment.systemPackages = [ pkgs.vim ];

    # Flakes
    nix = {
      package = pkgs.nixFlakes;
      extraOptions = "experimental-features = nix-command flakes";
    };
    ```

Install:

    ```console
    nixos-install
    ```

Set user password:

    ```console
    passwd joris
    ```

Reboot:

    ```console
    reboot
    ```

If the system doesn’t boot, boot from the USB key, and:

    ```console
    sudo su
    cryptsetup luksOpen /dev/<SYSTEM> crypted
    lvchange -a y /dev/vg/swap
    lvchange -a y /dev/vg/root
    mount /dev/vg/root /mnt
    mount /dev/<BOOT> /mnt/boot
    swapon /dev/vg/swap
    ```

# Import GPG key

Plug in recuperation key and check label with `lsblk`.

Decrypt and mount private backup:

    ```console
    sudo cryptsetup luksOpen /dev/XXX secrets
    sudo mkdir encrypted-storage
    sudo mount /dev/mapper/secrets encrypted-storage
    ```

Import:

    ```console
    gpg --import encrypted-storage/pubkey.asc
    gpg --allow-secret-key-import --import encrypted-storage/privkey.asc
    ```

Trust:

    ```console
    gpg --edit-key joris@guyonvarch.me
    gpg> trust
    ```

Write SSH keygrip in `~/.gnupg/sshcontrol`:

    ```console
    gpg2 -K --with-keygrip # [A] keygrip
    ```

Verify that SSH key is available:

    ```console
    ssh-add -L
    ```

Unmount and close the encrypted volume:

    ```console
    sudo umount encrypted-storage/
    sudo cryptsetup luksClose secret
    ```

Unplug the volume.

# Clone the system

Connect to Internet:

    ```console
    nmtui
    ```

Install git:

    ```console
    nix-env -i git
    ```

Clone the configuration:

    ```console
    git clone git@guyonvarch.me:/home/git/config /home/joris/code/config
    cd code/config
    git checkout main
    ```

Extract the system’s `hardware-configuration.nix`, and add it to `./hosts/joris/hardware/`.

Move aside the previous configuration:

    ```console
    cp -r /etc/nixos config-old
    sudo rm -rf /etc/nixos
    ```

Link `/etc/nixos` to the configuration:

    ```console
    sudo ln -s /home/joris/code/config /etc/nixos
    ```

Disable automatic export of documents if it’s not the principal system.

Change network interface in `hosts/network/joris/connman.nix`.

Remove `.gnupg/.sshcontrol`

Build:

    ```console
    nixos-rebuild switch
    ```

# Setup user environment

Create user directories:

    ```console
    mkdir code documents downloads music pictures videos
    ```

Create `.less` to setup less keybindings from `.lesskey`:

    ```console
    lesskey
    ```

Setup password store:

    ```console
    git clone git@guyonvarch.me:/home/git/password-store.git .password-store
    ```

Get documents:

    ```console
    duplicity restore rsync://guyonvarch.me/~/backups/documents documents
    ```

# Set up user services

Look at user services:

    ```console
    systemctl --user list-units
    systemctl --user list-timers --all
    ```

If services do not appear, run:

    ```console
    systemctl --user daemon-reload
    ```

# Check hardware acceleration

“OpenGL renderer string” should not be llvm:

    ```console
    nix-shell -p glxinfo --run "glxinfo | grep OpenGL"
    ```

# Synchronize

In order to link a device, use `cobang` to get the link from the QR code.

Then run:

    ```console
    signal-cli addDevice --uri "uri"
    ```

If you get `NotFoundException`, you may have been too slow in the process.