2019-09-13 02:35:38 +04:00
|
|
|
#!/usr/bin/env bash
|
2020-02-08 03:52:05 +04:00
|
|
|
cd ..
|
|
|
|
CONFIG_FOLDER=$(pwd)
|
|
|
|
cd install
|
2020-02-12 02:34:52 +04:00
|
|
|
NIXPKGS=$(nix eval --raw '(import ./nix/sources.nix).nixpkgs')
|
2020-01-23 01:29:27 +00:00
|
|
|
|
2019-10-10 20:11:05 +04:00
|
|
|
ENCRYPT_ROOT=true
|
2019-09-25 20:47:27 +04:00
|
|
|
FORMAT_BOOT_PARTITION=false
|
|
|
|
|
2019-10-10 20:11:05 +04:00
|
|
|
DEVICE_NAME=Dell-Laptop
|
2019-09-13 14:26:02 +04:00
|
|
|
DEVICE=/dev/nvme0n1
|
|
|
|
BOOT_PARTITION=/dev/nvme0n1p1
|
2019-09-23 14:04:13 +04:00
|
|
|
SWAP_PARTITION=/dev/nvme0n1p3
|
|
|
|
ROOT_PARTITION=/dev/nvme0n1p2
|
2019-09-22 22:40:08 +04:00
|
|
|
ROOT_NAME=cryptnixos
|
2019-09-13 02:35:38 +04:00
|
|
|
|
2019-09-13 14:26:02 +04:00
|
|
|
gdisk $DEVICE
|
2019-09-13 02:35:38 +04:00
|
|
|
|
2019-09-25 20:47:27 +04:00
|
|
|
# Format boot partition
|
|
|
|
if [[ "$FORMAT_BOOT_PARTITION" == true ]]; then
|
|
|
|
mkfs.vfat -n BOOT $BOOT_PARTITION
|
|
|
|
fi
|
|
|
|
# Create luks partition
|
|
|
|
if [[ "$ENCRYPT_ROOT" == true ]]; then
|
|
|
|
cryptsetup --type luks2 --cipher aes-xts-plain64 --key-size 256 --hash sha512 luksFormat $ROOT_PARTITION
|
2020-01-23 01:29:27 +00:00
|
|
|
cryptsetup luksOpen --type luks2 $ROOT_PARTITION $ROOT_NAME
|
2019-10-10 20:11:05 +04:00
|
|
|
ROOT_NAME=/dev/mapper/$ROOT_NAME
|
2019-09-26 02:46:10 +04:00
|
|
|
mkfs.btrfs -f -L root $ROOT_NAME
|
|
|
|
mount -t btrfs -o compress=zstd,noatime,ssd $ROOT_NAME /mnt
|
2019-09-25 20:47:27 +04:00
|
|
|
else
|
2019-09-26 02:46:10 +04:00
|
|
|
ROOT_NAME=$ROOT_PARTITION
|
2019-09-25 20:47:27 +04:00
|
|
|
mkfs.btrfs -f -L root $ROOT_PARTITION
|
2019-09-26 02:46:10 +04:00
|
|
|
mount -t btrfs -o compress=zstd,noatime,ssd $ROOT_PARTITION /mnt
|
2019-09-25 20:47:27 +04:00
|
|
|
fi
|
2019-09-22 22:40:08 +04:00
|
|
|
btrfs subvolume create /mnt/@nixos
|
|
|
|
btrfs subvolume create /mnt/@nix-store
|
|
|
|
btrfs subvolume create /mnt/@home
|
|
|
|
btrfs subvolume create /mnt/@snapshots
|
|
|
|
umount /mnt
|
2019-09-26 02:46:10 +04:00
|
|
|
mount -t btrfs -o subvol=@nixos,compress=zstd,noatime,ssd $ROOT_NAME /mnt/
|
2019-09-22 22:40:08 +04:00
|
|
|
mkdir -p /mnt/.snapshots
|
|
|
|
mkdir -p /mnt/home
|
|
|
|
mkdir -p /mnt/nix/store
|
2019-09-26 02:46:10 +04:00
|
|
|
mount -t btrfs -o subvol=@snapshots,compress=zstd,noatime,ssd $ROOT_NAME /mnt/.snapshots
|
|
|
|
mount -t btrfs -o subvol=@home,compress=zstd,noatime,ssd $ROOT_NAME /mnt/home
|
|
|
|
mount -t btrfs -o subvol=@nix-store,compress=zstd,noatime,ssd $ROOT_NAME /mnt/nix/store
|
2019-09-13 02:35:38 +04:00
|
|
|
btrfs subvolume create /mnt/tmp
|
2019-09-22 22:40:08 +04:00
|
|
|
btrfs subvolume create /mnt/var
|
2019-09-25 20:47:27 +04:00
|
|
|
# Mount boot
|
2019-09-13 02:35:38 +04:00
|
|
|
mkdir /mnt/boot
|
2019-09-13 14:26:02 +04:00
|
|
|
mount $BOOT_PARTITION /mnt/boot
|
2019-09-25 20:47:27 +04:00
|
|
|
# Create swap
|
2020-02-08 03:52:05 +04:00
|
|
|
mkswap -L swap $SWAP_PARTITION
|
2019-09-25 20:47:27 +04:00
|
|
|
# Generate config (hardware)
|
2019-09-13 02:35:38 +04:00
|
|
|
nixos-generate-config --root /mnt/
|
2020-01-23 01:29:27 +00:00
|
|
|
echo "import $CONFIG_FOLDER \"$DEVICE_NAME\"" > /mnt/etc/nixos/configuration.nix
|
|
|
|
nano /mnt/etc/nixos/configuration.nix
|
2019-09-25 20:47:27 +04:00
|
|
|
read -p "Please, add swap device into nixos-config/modules/filesystems.nix before continue"
|
2020-02-12 02:34:52 +04:00
|
|
|
nixos-install -I nixpkgs=$NIXPKGS
|
2019-09-23 14:04:13 +04:00
|
|
|
read -p "Press enter to continue"
|
2020-01-23 01:29:27 +00:00
|
|
|
mkdir -p /mnt/home/alukard/nixos-config
|
2020-02-08 03:52:05 +04:00
|
|
|
cp -aT $CONFIG_FOLDER /mnt/home/alukard/nixos-config
|
2020-02-12 02:34:52 +04:00
|
|
|
# chown -R 1000:100 /mnt/home/alukard/nixos-config
|
2020-02-08 03:52:05 +04:00
|
|
|
echo "import /home/alukard/nixos-config \"$DEVICE_NAME\"" > /mnt/etc/nixos/configuration.nix
|
2020-02-12 02:34:52 +04:00
|
|
|
echo "Installation complete!"
|