-
Notifications
You must be signed in to change notification settings - Fork 0
/
impermanence.nix
59 lines (47 loc) · 1.37 KB
/
impermanence.nix
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
# btrfs/impermanence.nix
{ config, pkgs, ... }:
let
myuser = config.myParams.myusername;
in
{
users.users.${myuser} = {
hashedPasswordFile = "/persist/passwords/user";
};
# filesystem modifications needed for impermanence
fileSystems."/persist".neededForBoot = true;
fileSystems."/var/log".neededForBoot = true;
fileSystems."/var/tmp".neededForBoot = true;
# reset / at each boot
# Note `lib.mkBefore` is used instead of `lib.mkAfter` here.
boot.initrd.postDeviceCommands = pkgs.lib.mkBefore ''
mkdir -p /mnt
# Mount the btrfs root to /mnt
mount -o subvol="@" /dev/vda3 /mnt
# Delete root subvolume
btrfs subvolume delete /mnt/root
# Restore new root from root-blank
btrfs subvolume snapshot /mnt/root-blank /mnt/root
# Unmount /mnt and continue boot process
umount /mnt
'';
# configure impermanence
environment.persistence."/persist" = {
directories = [
# "/etc/nixos"
"/etc/ssh"
];
files = [ ];
};
# machine id - setting as a persistent file results in errors.
# so we use this config option instead:
environment.etc.machine-id.source = /persist/etc/machine-id;
# security.sudo.extraConfig = ''
# # rollback results in sudo lectures after each reboot
# Defaults lecture = never
# '';
environment.sessionVariables = {
PATH = [
"/persist/nixos/scripts"
];
};
}