diff --git a/flake.nix b/flake.nix index 66e3544..78748bd 100644 --- a/flake.nix +++ b/flake.nix @@ -43,22 +43,12 @@ apps = self.lib.forAllSystems (system: with nixpkgs.legacyPackages.${system}; + let + binScript = x: writeShellScriptBin "script" "exec ${x}"; + in { - format-luks = writeShellScriptBin "format-luks" '' - set -e - read -p "Path to new LUKS device: " blkdev - set -x - cryptsetup -y -v luksFormat "$blkdev" - cryptsetup --allow-discards open "$blkdev" cryptroot - mkfs.btrfs /dev/mapper/cryptroot - mount /dev/mapper/cryptroot /mnt -o discard,compress=zstd - btrfs subvolume create /mnt/os - btrfs subvolume create /mnt/home - umount /mnt - mount /dev/mapper/cryptroot /mnt -o discard,compress=zstd,subvol=/os - mkdir /mnt/home - mount /dev/mapper/cryptroot /mnt/home -o discard,compress=zstd,subvol=/home - ''; + luks-mirror = binScript ./misc/luks-mirror.sh; + luks-single = binScript ./misc/luks-single.sh; } ); }; diff --git a/misc/luks-mirror.sh b/misc/luks-mirror.sh new file mode 100755 index 0000000..3705da0 --- /dev/null +++ b/misc/luks-mirror.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +set -e +read -p "Path to new LUKS device 1: " blkdevA +read -p "Path to new LUKS device 2: " blkdevB +set -x + +cryptsetup -y -v luksFormat "$blkdevA" +cryptsetup -y -v luksFormat "$blkdevB" +cryptsetup --allow-discards open "$blkdevA" cryptroot1 +cryptsetup --allow-discards open "$blkdevB" cryptroot2 + +mkfs.btrfs -f -L_root -mraid1 -draid1 /dev/mapper/cryptroot1 /dev/mapper/cryptroot2 +mount /dev/disk/by-label/_root /mnt -o discard,compress=zstd:1 + +btrfs subvolume create /mnt/home +btrfs subvolume create /mnt/nix +mkdir /mnt/boot diff --git a/misc/luks-single.sh b/misc/luks-single.sh new file mode 100755 index 0000000..b7e7014 --- /dev/null +++ b/misc/luks-single.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -e +read -p "Path to new LUKS device: " blkdev +set -x + +cryptsetup -y -v luksFormat "$blkdev" +cryptsetup --allow-discards open "$blkdev" cryptroot + +mkfs.btrfs -f -L_root /dev/mapper/cryptroot +mount /dev/disk/by-label/_root /mnt -o discard,compress=zstd:1 + +btrfs subvolume create /mnt/home +btrfs subvolume create /mnt/nix +mkdir /mnt/boot