aboutsummaryrefslogtreecommitdiff
path: root/docs/nixos-rebuild-onsite.adoc
blob: 80c858312c00789e321e6fae8cbcd8cb53058ea6 (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
= NixOS rebuild on the router

WARNING: This is pretty slow.

To rebuild NixOS directly on device something like 2GB of memory is required.
This pretty much is covered only by Turris Omnia 2G version and even that might
not be enough. Thus if you want to rebuild NixOS on the device you need the
SWAP. There is in default configure zram SWAP but that won't be enough. It is
highly suggested to create swap file of something like 2GB or 4GB size.

The creation and first addition of swap can be done like this (this expects that
used file-system is BTRFS):

[source,sh]
----
sudo truncate -s 4G /run/swap
sudo chattr +C /run/swap
sudo btrfs property set /run/swap compression none
sudo chmod 600 /run/swap
sudo mkswap /run/swap
sudo swapnon -p 0 /run/swap
----

Few notes here... Swap file is created by root and set to be accessible only by
root. For BTRFS the copy-on-write functionality is disabled and compression for
it. The swap itself is then added with lowest priority to prefer zram swap and
thus reduce real swap usage.

Do not forget to add this swap file to your NixOS configuration so it is added
on every boot. Edit file `/etc/nixos/configuration.nix` and add the following
lines:

[source,nix]
----
swapDevices = [
  {
    device = "/run/swap";
    priority = 0;
  }
];
----

Then you can pretty much manage it as any other NixOS device using
`nixos-rebuild` script running directly on the device, just very slowly.