From f3eb45a36180a5868e06f079b380d584029a0495 Mon Sep 17 00:00:00 2001 From: tristan Date: Mon, 8 Jan 2024 21:53:43 +0000 Subject: [PATCH] decryption function --- hardware/fcs-tristan-nixbook.nix | 18 +++++------------- hardware/zenix.nix | 21 +++++---------------- home/modules/terminal.nix | 2 +- home/programs/hyprland.nix | 3 +-- home/programs/sway.nix | 2 +- lib/decrypt.nix | 15 +++++++++++++++ nixos/modules/display.nix | 20 ++++++++++---------- 7 files changed, 38 insertions(+), 43 deletions(-) create mode 100644 lib/decrypt.nix diff --git a/hardware/fcs-tristan-nixbook.nix b/hardware/fcs-tristan-nixbook.nix index 148d479..963b6b5 100644 --- a/hardware/fcs-tristan-nixbook.nix +++ b/hardware/fcs-tristan-nixbook.nix @@ -6,6 +6,7 @@ ... }: let user = config.user; + decrypt = import ../lib/decrypt.nix; in { imports = [ (modulesPath + "/installer/scan/not-detected.nix") @@ -22,19 +23,10 @@ in { options = ["subvol=@" "compress=zstd" "autodefrag"]; }; - boot.initrd.postDeviceCommands = pkgs.lib.mkBefore '' - mkdir -m 0755 -p /key - - until cryptsetup luksOpen /dev/disk/by-id/usb-Generic_Flash_Disk_BCC97785-0:0 usbkey - do - echo "Failed to unlock usbkey!" - echo "Found block devices:" - ls /dev/disk/by-id/ - sleep 2 - done - - mount -n -t vfat -o ro /dev/mapper/usbkey /key - ''; + boot.initrd.postDeviceCommands = pkgs.lib.mkBefore (decrypt { + keydevice = "/dev/disk/by-id/usb-Generic_Flash_Disk_BCC97785-0:0"; + keypartname = "usbkey"; + }); boot.initrd.luks.devices."cryptroot" = { device = "/dev/disk/by-uuid/570cc51f-bd5c-4bee-a18f-f6aabaf60881"; diff --git a/hardware/zenix.nix b/hardware/zenix.nix index 318178e..d547c00 100644 --- a/hardware/zenix.nix +++ b/hardware/zenix.nix @@ -6,6 +6,7 @@ ... }: let user = config.user; + decrypt = import ../lib/decrypt.nix; in { imports = [ (modulesPath + "/installer/scan/not-detected.nix") @@ -24,22 +25,10 @@ in { options = ["subvol=@" "compress=zstd" "autodefrag"]; }; - boot.initrd.postDeviceCommands = pkgs.lib.mkBefore '' - mkdir -m 0755 -p /key - - dev=/dev/disk/by-id/usb-Generic_Flash_Disk_BCC97785-0:0 - sleep 1 - until cryptsetup luksOpen "$dev" usbkey - do - echo "Insert key and press enter..." - read res - if test "$res" = "fzf" - then - ls /dev/disk/by-id | ${pkgs.fzf}/bin/fzf - fi - done - mount -n -t vfat -o ro /dev/mapper/usbkey /key - ''; + boot.initrd.postDeviceCommands = pkgs.lib.mkBefore (decrypt { + keydevice = "/dev/disk/by-id/usb-Generic_Flash_Disk_BCC97785-0:0"; + keypartname = "usbkey"; + }); boot.initrd.luks.devices."cryptroot" = { device = "/dev/disk/by-uuid/cc0617df-8cbf-4618-abbc-df64c96de151"; diff --git a/home/modules/terminal.nix b/home/modules/terminal.nix index e7bc66b..3b6101e 100644 --- a/home/modules/terminal.nix +++ b/home/modules/terminal.nix @@ -5,7 +5,7 @@ ... }: let term = config.programs.terminal; - termcmd = "${ config.programs.terminal }/bin/${config.programs.terminal.pname}"; + termcmd = "${config.programs.terminal}/bin/${config.programs.terminal.pname}"; in { options.programs = { terminal = lib.mkPackageOption pkgs "foot" { diff --git a/home/programs/hyprland.nix b/home/programs/hyprland.nix index 9d1bd63..7a756b0 100644 --- a/home/programs/hyprland.nix +++ b/home/programs/hyprland.nix @@ -5,13 +5,12 @@ ... }: let modifier = config.windowManager.modifierKey; - in { imports = [ (import ./swaylock.nix) (import ./swayidle.nix) (import ./waybar.nix) - (import ./hycov.nix) + # (import ./hycov.nix) ]; xdg.portal = { enable = true; diff --git a/home/programs/sway.nix b/home/programs/sway.nix index cb24378..bba5e60 100644 --- a/home/programs/sway.nix +++ b/home/programs/sway.nix @@ -3,7 +3,7 @@ config, ... }: let - term = "${ config.programs.terminal }/bin/${config.programs.terminal.pname}"; + term = "${config.programs.terminal}/bin/${config.programs.terminal.pname}"; modKeyName = config.windowManager.modifierKey; modifier = if modKeyName == "SUPER" diff --git a/lib/decrypt.nix b/lib/decrypt.nix new file mode 100644 index 0000000..47a2965 --- /dev/null +++ b/lib/decrypt.nix @@ -0,0 +1,15 @@ +{ + keydevice, + keypartname, +}: '' + mkdir -m 0755 -p /key + + dev=${keydevice} + sleep 1 + until cryptsetup luksOpen "$dev" usbkey + do + echo "Insert key and press enter..." + read res + done + mount -n -t vfat -o ro /dev/mapper/${keypartname} /key +'' diff --git a/nixos/modules/display.nix b/nixos/modules/display.nix index 2f5e144..104ba26 100644 --- a/nixos/modules/display.nix +++ b/nixos/modules/display.nix @@ -62,16 +62,16 @@ with lib; let name = display.name; value = let res = display.resolution; - in { - mode = - mkIf (!resUnset res) - "${toString res.x}x${toString res.y}@${toString res.freq}Hz"; - scale = toString display.scaling; - } - // lib.mkIf ( display ? wallpaper && display.wallpaper != null ) { - bg = "${ display.wallpaper } fill"; - } - ; + in + { + mode = + mkIf (!resUnset res) + "${toString res.x}x${toString res.y}@${toString res.freq}Hz"; + scale = toString display.scaling; + } + // lib.mkIf (display ? wallpaper && display.wallpaper != null) { + bg = "${display.wallpaper} fill"; + }; }; resolutionType = types.submodule {