mirror of
https://github.com/Swarsel/.dotfiles.git
synced 2025-12-06 09:07:21 +01:00
feat: option for unencrypted Impermanence
This commit is contained in:
parent
e4d507d5c1
commit
43e13334c0
8 changed files with 216 additions and 196 deletions
|
|
@ -9,7 +9,9 @@ in
|
|||
"${self}/hosts/nixos/toto/disk-config.nix"
|
||||
{
|
||||
_module.args = {
|
||||
withSwap = false;
|
||||
withSwap = true;
|
||||
swapSize = "8";
|
||||
rootDisk = "/dev/vda";
|
||||
withImpermanence = true;
|
||||
withEncryption = false;
|
||||
};
|
||||
|
|
@ -17,12 +19,14 @@ in
|
|||
./hardware-configuration.nix
|
||||
|
||||
inputs.sops-nix.nixosModules.sops
|
||||
inputs.impermanence.nixosModules.impermanence
|
||||
|
||||
"${profilesPath}/optional/nixos/autologin.nix"
|
||||
"${profilesPath}/common/nixos/settings.nix"
|
||||
"${profilesPath}/common/nixos/home-manager.nix"
|
||||
"${profilesPath}/common/nixos/xserver.nix"
|
||||
"${profilesPath}/common/nixos/users.nix"
|
||||
"${profilesPath}/common/nixos/impermanence.nix"
|
||||
"${profilesPath}/common/nixos/sops.nix"
|
||||
"${profilesPath}/server/nixos/ssh.nix"
|
||||
|
||||
|
|
@ -75,14 +79,15 @@ in
|
|||
swarselsystems = {
|
||||
wallpaper = self + /wallpaper/lenovowp.png;
|
||||
impermanence = true;
|
||||
isBtrfs = false;
|
||||
isBtrfs = true;
|
||||
isCrypted = false;
|
||||
initialSetup = true;
|
||||
};
|
||||
|
||||
home-manager.users.swarsel.swarselsystems = {
|
||||
isLaptop = false;
|
||||
isNixos = true;
|
||||
isBtrfs = false;
|
||||
isBtrfs = true;
|
||||
flakePath = "/home/swarsel/.dotfiles";
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,18 +1,69 @@
|
|||
# NOTE: ... is needed because dikso passes diskoFile
|
||||
{ lib
|
||||
, pkgs
|
||||
, swapSize
|
||||
, rootDisk
|
||||
, swapSize ? "8"
|
||||
, withSwap ? true
|
||||
, withEncryption ? true
|
||||
, withImpermanence ? true
|
||||
, ...
|
||||
}:
|
||||
let
|
||||
type = "btrfs";
|
||||
extraArgs = [ "-L" "nixos" "-f" ]; # force overwrite
|
||||
subvolumes = {
|
||||
"/root" = {
|
||||
mountpoint = "/";
|
||||
mountOptions = [
|
||||
"subvol=root"
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
};
|
||||
"/home" = lib.mkIf withImpermanence {
|
||||
mountpoint = "/home";
|
||||
mountOptions = [
|
||||
"subvol=home"
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
};
|
||||
"/persist" = lib.mkIf withImpermanence {
|
||||
mountpoint = "/persist";
|
||||
mountOptions = [
|
||||
"subvol=persist"
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
};
|
||||
"/log" = lib.mkIf withImpermanence {
|
||||
mountpoint = "/var/log";
|
||||
mountOptions = [
|
||||
"subvol=log"
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
};
|
||||
"/nix" = {
|
||||
mountpoint = "/nix";
|
||||
mountOptions = [
|
||||
"subvol=nix"
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
};
|
||||
"/swap" = lib.mkIf withSwap {
|
||||
mountpoint = "/.swapvol";
|
||||
swap.swapfile.size = "${swapSize}G";
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
disko.devices = {
|
||||
disk = {
|
||||
disk0 = {
|
||||
type = "disk";
|
||||
device = "/dev/vda";
|
||||
device = rootDisk;
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
|
|
@ -31,41 +82,13 @@
|
|||
root = lib.mkIf (!withEncryption) {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "btrfs";
|
||||
extraArgs = [ "-f" ]; # force overwrite
|
||||
inherit type subvolumes extraArgs;
|
||||
postCreateHook = lib.mkIf withImpermanence ''
|
||||
MNTPOINT=$(mktemp -d)
|
||||
mount "/dev/mapper/root" "$MNTPOINT" -o subvol=/
|
||||
MNTPOINT=$(mktemp -d)
|
||||
mount "/dev/disk/by-label/nixos" "$MNTPOINT" -o subvolid=5
|
||||
trap 'umount $MNTPOINT; rm -rf $MNTPOINT' EXIT
|
||||
btrfs subvolume snapshot -r $MNTPOINT/root $MNTPOINT/root-blank
|
||||
'';
|
||||
subvolumes = {
|
||||
"@root" = {
|
||||
mountpoint = "/";
|
||||
mountOptions = [
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
};
|
||||
"@persist" = lib.mkIf withImpermanence {
|
||||
mountpoint = "/persist";
|
||||
mountOptions = [
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
};
|
||||
"@nix" = {
|
||||
mountpoint = "/nix";
|
||||
mountOptions = [
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
};
|
||||
"@swap" = lib.mkIf withSwap {
|
||||
mountpoint = "/.swapvol";
|
||||
swap.swapfile.size = "${swapSize}G";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
luks = lib.mkIf withEncryption {
|
||||
|
|
@ -73,7 +96,7 @@
|
|||
content = {
|
||||
type = "luks";
|
||||
name = "cryptroot";
|
||||
passwordFile = "/tmp/disko-password"; # this is populated by bootstrap-nixos.sh
|
||||
passwordFile = "/tmp/disko-password"; # this is populated by bootstrap.sh
|
||||
settings = {
|
||||
allowDiscards = true;
|
||||
# https://github.com/hmajid2301/dotfiles/blob/a0b511c79b11d9b4afe2a5e2b7eedb2af23e288f/systems/x86_64-linux/framework/disks.nix#L36
|
||||
|
|
@ -82,44 +105,14 @@
|
|||
"token-timeout=10"
|
||||
];
|
||||
};
|
||||
# Subvolumes must set a mountpoint in order to be mounted,
|
||||
# unless their parent is mounted
|
||||
content = {
|
||||
type = "btrfs";
|
||||
extraArgs = [ "-f" ]; # force overwrite
|
||||
inherit type subvolumes extraArgs;
|
||||
postCreateHook = lib.mkIf withImpermanence ''
|
||||
MNTPOINT=$(mktemp -d)
|
||||
mount "/dev/mapper/cryptroot" "$MNTPOINT" -o subvol=/
|
||||
MNTPOINT=$(mktemp -d)
|
||||
mount "/dev/mapper/cryptroot" "$MNTPOINT" -o subvolid=5
|
||||
trap 'umount $MNTPOINT; rm -rf $MNTPOINT' EXIT
|
||||
btrfs subvolume snapshot -r $MNTPOINT/root $MNTPOINT/root-blank
|
||||
'';
|
||||
subvolumes = {
|
||||
"@root" = {
|
||||
mountpoint = "/";
|
||||
mountOptions = [
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
};
|
||||
"@persist" = lib.mkIf withImpermanence {
|
||||
mountpoint = "/persist";
|
||||
mountOptions = [
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
};
|
||||
"@nix" = {
|
||||
mountpoint = "/nix";
|
||||
mountOptions = [
|
||||
"compress=zstd"
|
||||
"noatime"
|
||||
];
|
||||
};
|
||||
"@swap" = lib.mkIf withSwap {
|
||||
mountpoint = "/.swapvol";
|
||||
swap.swapfile.size = "${swapSize}G";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
@ -130,8 +123,9 @@
|
|||
};
|
||||
|
||||
fileSystems."/persist".neededForBoot = lib.mkIf withImpermanence true;
|
||||
fileSystems."/home".neededForBoot = lib.mkIf withImpermanence true;
|
||||
|
||||
environment.systemPackages = [
|
||||
pkgs.yubikey-manager # For luks fido2 enrollment before full install
|
||||
pkgs.yubikey-manager
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue