support unencrypted disk provisioning
This commit is contained in:
parent
2a5495f9bb
commit
2a2715d447
11 changed files with 69 additions and 39 deletions
11
Justfile
11
Justfile
|
@ -196,22 +196,21 @@ hm-iterate-qtile:
|
||||||
|
|
||||||
# !!! DANGERIOUS !!! This wipes the disk which is configured for the given device.
|
# !!! DANGERIOUS !!! This wipes the disk which is configured for the given device.
|
||||||
disk-prepare dir:
|
disk-prepare dir:
|
||||||
just -v _device diskPrepare {{dir}} --argstr rebuildarg "dummy"
|
just -v _device diskPrepare {{dir}}
|
||||||
|
|
||||||
disk-relabel dir previous:
|
disk-relabel dir previous:
|
||||||
just -v _device diskRelabel {{dir}} --argstr rebuildarg "dummy" --argstr previousDiskId {{previous}}
|
just -v _device diskRelabel {{dir}} --argstr previousDiskId {{previous}}
|
||||||
|
|
||||||
# Mount the target disk specified by device configuration directory. The 'dir' argument points to a device configuration, e.g. 'nix/os/devices/steveej-live-mmc-SL32G_0x259093f6'
|
# Mount the target disk specified by device configuration directory. The 'dir' argument points to a device configuration, e.g. 'nix/os/devices/steveej-live-mmc-SL32G_0x259093f6'
|
||||||
disk-mount dir:
|
disk-mount dir:
|
||||||
just -v _device diskMount {{dir}} --argstr rebuildarg "dummy"
|
just -v _device diskMount {{dir}}
|
||||||
|
|
||||||
# Unmount target disk, specified by device configuration directory
|
# Unmount target disk, specified by device configuration directory
|
||||||
disk-umount dir:
|
disk-umount dir:
|
||||||
just -v _device diskUmount {{dir}} --argstr rebuildarg "dummy"
|
just -v _device diskUmount {{dir}}
|
||||||
|
|
||||||
# Perform an offline installation on the mounted target disk, specified by device configuration directory
|
# Perform an offline installation on the mounted target disk, specified by device configuration directory
|
||||||
disk-install dir: _render_templates
|
disk-install dir: _render_templates
|
||||||
just -v _device diskInstall {{dir}} --argstr rebuildarg "dummy"
|
just -v _device diskInstall {{dir}}
|
||||||
|
|
||||||
verify-n-unlock sshserver attempts="10":
|
verify-n-unlock sshserver attempts="10":
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
{ pkgs ? import <channels-nixos-stable> {}
|
{ dir
|
||||||
|
, pkgs ? import <channels-nixos-stable> {}
|
||||||
, ownLib ? import ../lib/default.nix { }
|
, ownLib ? import ../lib/default.nix { }
|
||||||
, dir
|
|
||||||
, rebuildarg
|
|
||||||
, moreargs ? ""
|
|
||||||
, diskId ? (import ((builtins.getEnv "PWD")+"/${dir}/hw.nix") {}).hardware.encryptedDisk.diskId
|
|
||||||
, gitRoot ? "$(git rev-parse --show-toplevel)"
|
, gitRoot ? "$(git rev-parse --show-toplevel)"
|
||||||
, previousDiskId ? ""
|
|
||||||
}:
|
# FIXME: why do these need explicit mentioning?
|
||||||
|
, moreargs ? null
|
||||||
|
, rebuildarg ? ""
|
||||||
|
, ...
|
||||||
|
} @ args :
|
||||||
|
|
||||||
let
|
let
|
||||||
rebuildargsSudo = [ "switch" "boot" ];
|
rebuildargsSudo = [ "switch" "boot" ];
|
||||||
rebuild = pkgs.writeScript "script" ''
|
rebuild = {
|
||||||
|
rebuildarg
|
||||||
|
, gitRoot
|
||||||
|
, moreargs ? null
|
||||||
|
|
||||||
|
, ...
|
||||||
|
}: pkgs.writeScript "script" ''
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -xe
|
set -xe
|
||||||
|
|
||||||
|
@ -35,6 +42,7 @@ let
|
||||||
|
|
||||||
in {
|
in {
|
||||||
recipes = {
|
recipes = {
|
||||||
inherit rebuild;
|
rebuild = rebuild { inherit gitRoot; inherit (args) rebuildarg moreargs; };
|
||||||
} // (import ./disk.nix { inherit pkgs ownLib dir rebuildarg moreargs diskId gitRoot previousDiskId; });
|
} // (import ./disk.nix (args // { inherit pkgs ownLib gitRoot; }))
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
{ pkgs
|
{ pkgs
|
||||||
, ownLib
|
, ownLib
|
||||||
, dir
|
, dir
|
||||||
, rebuildarg
|
|
||||||
, moreargs
|
|
||||||
, diskId
|
|
||||||
, gitRoot
|
, gitRoot
|
||||||
|
, diskId ? (import ((builtins.getEnv "PWD")+"/${dir}/hw.nix") {}).hardware.opinionatedDisk.diskId
|
||||||
|
, encrypted ? (import ((builtins.getEnv "PWD")+"/${dir}/hw.nix") {}).hardware.opinionatedDisk.encrypted
|
||||||
, previousDiskId ? ""
|
, previousDiskId ? ""
|
||||||
|
|
||||||
|
, ...
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
|
@ -16,7 +17,9 @@ in rec {
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -xe
|
set -xe
|
||||||
echo Mounting ${diskId}
|
echo Mounting ${diskId}
|
||||||
|
${pkgs.lib.strings.optionalString encrypted ''
|
||||||
sudo cryptsetup luksOpen ${ownLib.disk.bootLuksDevice diskId} ${ownLib.disk.luksName diskId}
|
sudo cryptsetup luksOpen ${ownLib.disk.bootLuksDevice diskId} ${ownLib.disk.luksName diskId}
|
||||||
|
''}
|
||||||
sleep 1
|
sleep 1
|
||||||
sudo vgchange -ay ${ownLib.disk.volumeGroup diskId}
|
sudo vgchange -ay ${ownLib.disk.volumeGroup diskId}
|
||||||
sudo mkdir -p /mnt
|
sudo mkdir -p /mnt
|
||||||
|
@ -32,7 +35,9 @@ in rec {
|
||||||
sudo umount -Rl ${mntRootVol}
|
sudo umount -Rl ${mntRootVol}
|
||||||
sudo rmdir ${mntRootVol}
|
sudo rmdir ${mntRootVol}
|
||||||
sudo vgchange -an ${ownLib.disk.volumeGroup diskId}
|
sudo vgchange -an ${ownLib.disk.volumeGroup diskId}
|
||||||
|
${pkgs.lib.strings.optionalString encrypted ''
|
||||||
sudo cryptsetup close ${ownLib.disk.luksName diskId}
|
sudo cryptsetup close ${ownLib.disk.luksName diskId}
|
||||||
|
''}
|
||||||
sync
|
sync
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
@ -56,7 +61,7 @@ in rec {
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -xe
|
set -xe
|
||||||
|
|
||||||
read -p "Continue to format ${ownLib.disk.bootGrubDevice diskId} (YES/n)?" choice
|
read -p "Continue to format ${ownLib.disk.bootGrubDevice diskId} (YES/n)? " choice
|
||||||
case "$choice" in
|
case "$choice" in
|
||||||
YES ) echo "Continuing in 3 seconds..."; sleep 3;;
|
YES ) echo "Continuing in 3 seconds..."; sleep 3;;
|
||||||
n|N ) echo "Exiting..."; exit 0;;
|
n|N ) echo "Exiting..."; exit 0;;
|
||||||
|
@ -100,12 +105,14 @@ in rec {
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
|
${pkgs.lib.strings.optionalString encrypted ''
|
||||||
# Encrypt
|
# Encrypt
|
||||||
sudo cryptsetup luksFormat ${ownLib.disk.bootLuksDevice diskId} -
|
sudo cryptsetup luksFormat ${ownLib.disk.bootLuksDevice diskId} -
|
||||||
sudo cryptsetup luksOpen ${ownLib.disk.bootLuksDevice diskId} ${ownLib.disk.luksName diskId}
|
sudo cryptsetup luksOpen ${ownLib.disk.bootLuksDevice diskId} ${ownLib.disk.luksName diskId}
|
||||||
|
''}
|
||||||
|
|
||||||
# LVM
|
# LVM
|
||||||
sudo vgcreate ${ownLib.disk.volumeGroup diskId} ${ownLib.disk.luksPhysicalVolume diskId}
|
sudo vgcreate ${ownLib.disk.volumeGroup diskId} ${ownLib.disk.lvmPv diskId encrypted}
|
||||||
sudo lvcreate ${ownLib.disk.volumeGroup diskId} -L 2G -n swap
|
sudo lvcreate ${ownLib.disk.volumeGroup diskId} -L 2G -n swap
|
||||||
sudo lvcreate ${ownLib.disk.volumeGroup diskId} -l 100%FREE -n root
|
sudo lvcreate ${ownLib.disk.volumeGroup diskId} -l 100%FREE -n root
|
||||||
|
|
||||||
|
@ -160,7 +167,9 @@ in rec {
|
||||||
|
|
||||||
|
|
||||||
if test "${previousDiskId}"; then
|
if test "${previousDiskId}"; then
|
||||||
|
${pkgs.lib.strings.optionalString encrypted ''
|
||||||
sudo cryptsetup luksOpen ${ownLib.disk.bootLuksDevice diskId} ${ownLib.disk.luksName diskId}
|
sudo cryptsetup luksOpen ${ownLib.disk.bootLuksDevice diskId} ${ownLib.disk.luksName diskId}
|
||||||
|
''}
|
||||||
sync
|
sync
|
||||||
sleep 1
|
sleep 1
|
||||||
if sudo vgs ${previousDiskId}; then
|
if sudo vgs ${previousDiskId}; then
|
||||||
|
@ -168,6 +177,8 @@ in rec {
|
||||||
sudo vgscan
|
sudo vgscan
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
${pkgs.lib.strings.optionalString encrypted ''
|
||||||
sudo cryptsetup close ${ownLib.disk.luksName diskId}
|
sudo cryptsetup close ${ownLib.disk.luksName diskId}
|
||||||
|
''}
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
imports = [
|
imports = [
|
||||||
../../profiles/common/configuration.nix
|
../../profiles/common/configuration.nix
|
||||||
../../profiles/graphical/configuration.nix
|
../../profiles/graphical/configuration.nix
|
||||||
../../modules/encryptedDisk.nix
|
../../modules/opnionatedDisk.nix
|
||||||
|
|
||||||
./system.nix
|
./system.nix
|
||||||
./hw.nix
|
./hw.nix
|
||||||
|
|
|
@ -20,6 +20,7 @@ in
|
||||||
# TASK: new device
|
# TASK: new device
|
||||||
hardware.encryptedDisk = {
|
hardware.encryptedDisk = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
encrypted = true;
|
||||||
diskId = "nvme-SKHynix_HFS001TD9TNI-L2B0B_CJ0AN89731030AV3Q";
|
diskId = "nvme-SKHynix_HFS001TD9TNI-L2B0B_CJ0AN89731030AV3Q";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
];
|
];
|
||||||
imports = [
|
imports = [
|
||||||
../../profiles/common/configuration.nix
|
../../profiles/common/configuration.nix
|
||||||
../../modules/encryptedDisk.nix
|
../../modules/opinionatedDisk.nix
|
||||||
|
|
||||||
./system.nix
|
./system.nix
|
||||||
./hw.nix
|
./hw.nix
|
||||||
|
|
|
@ -18,8 +18,9 @@ let
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# TASK: new device
|
# TASK: new device
|
||||||
hardware.encryptedDisk = {
|
hardware.opinionatedDisk = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
encrypted = true;
|
||||||
diskId = "scsi-0QEMU_QEMU_HARDDISK_drive-scsi0";
|
diskId = "scsi-0QEMU_QEMU_HARDDISK_drive-scsi0";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -48,5 +48,10 @@
|
||||||
bootLuksDevice = diskId: "/dev/disk/by-partlabel/" + (shortenGptPartlabel ("3-"+diskId));
|
bootLuksDevice = diskId: "/dev/disk/by-partlabel/" + (shortenGptPartlabel ("3-"+diskId));
|
||||||
luksName = diskId: (volumeGroup diskId)+"pv";
|
luksName = diskId: (volumeGroup diskId)+"pv";
|
||||||
luksPhysicalVolume = diskId: "/dev/mapper/" + (luksName diskId);
|
luksPhysicalVolume = diskId: "/dev/mapper/" + (luksName diskId);
|
||||||
|
lvmPv = diskId: encrypted:
|
||||||
|
if encrypted == true
|
||||||
|
then luksPhysicalVolume diskId
|
||||||
|
else bootLuksDevice diskId
|
||||||
|
;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,14 +4,18 @@
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.hardware.encryptedDisk;
|
cfg = config.hardware.opinionatedDisk;
|
||||||
ownLib = import ../lib/default.nix { };
|
ownLib = import ../lib/default.nix { };
|
||||||
in {
|
in {
|
||||||
options.hardware.encryptedDisk = {
|
options.hardware.opinionatedDisk = {
|
||||||
enable = mkEnableOption "Enable encrypted filesystem layout";
|
enable = mkEnableOption "Enable opinionated filesystem layout";
|
||||||
diskId = mkOption {
|
diskId = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
};
|
};
|
||||||
|
encrypted = mkOption {
|
||||||
|
default = true;
|
||||||
|
type = types.bool;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
|
@ -36,10 +40,10 @@ in {
|
||||||
|
|
||||||
boot.loader.grub = {
|
boot.loader.grub = {
|
||||||
device = (ownLib.disk.bootGrubDevice cfg.diskId);
|
device = (ownLib.disk.bootGrubDevice cfg.diskId);
|
||||||
enableCryptodisk = true;
|
enableCryptodisk = cfg.encrypted;
|
||||||
};
|
};
|
||||||
|
|
||||||
boot.initrd.luks.devices = builtins.listToAttrs [
|
boot.initrd.luks.devices = lib.optionalAttrs cfg.encrypted (builtins.listToAttrs [
|
||||||
{
|
{
|
||||||
name =
|
name =
|
||||||
let
|
let
|
||||||
|
@ -53,6 +57,6 @@ in {
|
||||||
allowDiscards = true;
|
allowDiscards = true;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
];
|
]);
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
../../modules/encryptedDisk.nix
|
../../modules/opinionatedDisk.nix
|
||||||
|
|
||||||
./pkg.nix
|
./pkg.nix
|
||||||
./hw.nix
|
./hw.nix
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
{ ... }:
|
{ ... }:
|
||||||
|
|
||||||
{
|
{
|
||||||
hardware.encryptedDisk.enable = true;
|
hardware.opnionatedDisk.enable = true;
|
||||||
|
hardware.opnionatedDisk.encrypted = true;
|
||||||
hardware.enableAllFirmware = true;
|
hardware.enableAllFirmware = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue