add encrypted usb and move paths to data files

This commit is contained in:
ChaotiCryptidz 2022-02-15 11:02:07 +00:00
parent 581e70042e
commit 8ae4ad026a
4 changed files with 78 additions and 22 deletions

View file

@ -1,8 +1,7 @@
{ pkgs, ... }: { pkgs, ... }:
let let
usb_label = "my_usb"; usb_data = import ./hardware/usb_data.nix {};
encrypted_root_partlabel = "nixos_encrypted"; ssd_data = import ./hardware/ssd_data.nix {};
unencrypted_root_uuid = "";
in { in {
boot = { boot = {
loader = { loader = {
@ -29,33 +28,39 @@ in {
initrd.postDeviceCommands = pkgs.lib.mkBefore '' initrd.postDeviceCommands = pkgs.lib.mkBefore ''
mkdir -m 0755 -p /key mkdir -m 0755 -p ${usb_data.mountpoint}
while !(findfs LABEL=${usb_label})
while !(test -b ${usb_data.encrypted_path})
do do
echo "Please Plug In USB" echo "Please Plug In USB"
sleep 1 sleep 1
done done
mount -n -t vfat -o ro `findfs LABEL=${usb_label}` /key
echo "Please Decrypt USB"
cryptsetup luksOpen ${usb_data.encrypted_path} ${usb_data.mapper_name}
mount -n -t ${usb_data.unencrypted_fs_type} -o ro ${usb_data.mapper_path} ${usb_data.mountpoint}
''; '';
initrd.luks.devices."cryptroot".device = initrd.luks.devices = {
"/dev/disk/by-partlabel/${encrypted_root_partlabel}"; "${ssd_data.root_mapper_name}" = {
device = "${ssd_data.encrypted_root_path}";
initrd.luks.devices."cryptroot" = { keyFile = "${usb_data.lappy_encryption_key_path}";
keyFile = "/key/encryption-keys/lappy.key";
preLVM = false; preLVM = false;
allowDiscards = true; allowDiscards = true;
}; };
}; };
};
fileSystems = { fileSystems = {
"/" = { "/" = {
device = "/dev/mapper/cryptroot"; device = "${ssd_data.decrypted_root_path}";
fsType = "ext4"; fsType = "${ssd_data.unencrypted_root_fs_type}";
}; };
"/boot" = { "/boot" = {
device = "/dev/disk/by-label/nixboot"; device = "${ssd_data.boot_path}";
fsType = "vfat"; fsType = "${ssd_data.boot_fs_type}";
}; };
}; };

View file

@ -0,0 +1,23 @@
{}: rec {
# Mountpoints
root_mountpoint = "/";
boot_mountpoint = "/boot";
# Partition Labels
boot_label = "nixboot";
encrypted_root_partlabel = "nixos_encrypted";
# Partition Filesystems
unencrypted_root_fs_type = "ext4";
boot_fs_type = "vfat";
# Mapper Name
root_mapper_name = "cryptroot";
# FS Paths
encrypted_root_path = "/dev/disk/by-partlabel/${encrypted_root_partlabel}";
decrypted_root_path = "/dev/mapper/${root_mapper_name}";
boot_path = "/dev/disk/by-label/${boot_label}";
}

View file

@ -0,0 +1,24 @@
{...}: rec {
# Mountpoints
mountpoint = "/usb";
# Partition Labels
encrypted_partlabel = "usb";
unencrypted_label = "usb_unencrypted";
# Partition Filesystems
unencrypted_fs_type = "ext4";
# Mapper Information
mapper_name = "usb_unencrypted";
# FS Paths
encrypted_path = "/dev/disk/by-partlabel/${encrypted_partlabel}";
unencrypted_path = "/dev/disk/by-label/${unencrypted_label}";
mapper_path = "/dev/mapper/${mapper_name}";
# Paths to some important files
lappy_encryption_key_path = "${mountpoint}/encryption-keys/lappy.key";
}

View file

@ -9,7 +9,7 @@
#profiles.printing #profiles.printing
profiles.sshd profiles.sshd
hosts.lappy.profiles.usb-automount #hosts.lappy.profiles.usb-automount
# required for dualsense controller # required for dualsense controller
profiles.kernels.latest profiles.kernels.latest
@ -80,21 +80,25 @@
intel-media-driver intel-media-driver
]; ];
services.getty.extraArgs = [ "--skip-login" "--login-options" "chaos" ];
services.getty.extraArgs =
[ "--skip-login" "--login-options" "chaos" ];
networking.firewall.enable = true; networking.firewall.enable = true;
# let vscode, vivaldi, etc work. # let vscode, vivaldi, etc work.
security.unprivilegedUsernsClone = true; security.unprivilegedUsernsClone = true;
nix.settings.auto-optimise-store = true;
nix.gc = {
automatic = true;
dates = "daily";
options = "--delete-older-than 4d";
};
networking.hostName = "lappy"; networking.hostName = "lappy";
time.timeZone = "Europe/London"; time.timeZone = "Europe/London";
powerManagement.cpuFreqGovernor = lib.mkDefault "powersave"; powerManagement.cpuFreqGovernor = lib.mkDefault "powersave";
services.fstrim.enable = true; services.fstrim.enable = true;
system.stateVersion = "21.11"; system.stateVersion = "21.11";
} }