add disko
This commit is contained in:
		
							parent
							
								
									a7f6983abe
								
							
						
					
					
						commit
						3c09386643
					
				
					 3 changed files with 45 additions and 63 deletions
				
			
		| 
						 | 
					@ -38,6 +38,9 @@
 | 
				
			||||||
      inputs.nixpkgs.follows = "nixpkgs";
 | 
					      inputs.nixpkgs.follows = "nixpkgs";
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    inputs.disko.url = "github:nix-community/disko";
 | 
				
			||||||
 | 
					    inputs.disko.inputs.nixpkgs.follows = "nixpkgs";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # my stuff
 | 
					    # my stuff
 | 
				
			||||||
    dhist = {
 | 
					    dhist = {
 | 
				
			||||||
      url = "github:lelgenio/dhist";
 | 
					      url = "github:lelgenio/dhist";
 | 
				
			||||||
| 
						 | 
					@ -96,6 +99,7 @@
 | 
				
			||||||
          inputs.agenix.nixosModules.default
 | 
					          inputs.agenix.nixosModules.default
 | 
				
			||||||
          inputs.dzgui-nix.nixosModules.default
 | 
					          inputs.dzgui-nix.nixosModules.default
 | 
				
			||||||
          inputs.home-manager.nixosModules.home-manager
 | 
					          inputs.home-manager.nixosModules.home-manager
 | 
				
			||||||
 | 
					          inputs.disko.nixosModules.disko
 | 
				
			||||||
          {
 | 
					          {
 | 
				
			||||||
            home-manager.useGlobalPkgs = true;
 | 
					            home-manager.useGlobalPkgs = true;
 | 
				
			||||||
            home-manager.useUserPackages = true;
 | 
					            home-manager.useUserPackages = true;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										41
									
								
								hosts/partition/i15.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								hosts/partition/i15.nix
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,41 @@
 | 
				
			||||||
 | 
					{ disks ? [ "/dev/sda" ], ... }: {
 | 
				
			||||||
 | 
					  disk.sda = {
 | 
				
			||||||
 | 
					    type = "disk";
 | 
				
			||||||
 | 
					    device = builtins.elemAt disks 0;
 | 
				
			||||||
 | 
					    content = {
 | 
				
			||||||
 | 
					      type = "table";
 | 
				
			||||||
 | 
					      format = "gpt";
 | 
				
			||||||
 | 
					      partitions = [
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          type = "partition";
 | 
				
			||||||
 | 
					          name = "NIX_BOOT";
 | 
				
			||||||
 | 
					          start = "1MiB";
 | 
				
			||||||
 | 
					          end = "1GiB";
 | 
				
			||||||
 | 
					          bootable = true;
 | 
				
			||||||
 | 
					          content = {
 | 
				
			||||||
 | 
					            type = "filesystem";
 | 
				
			||||||
 | 
					            format = "vfat";
 | 
				
			||||||
 | 
					            mountpoint = "/boot";
 | 
				
			||||||
 | 
					            options = [ "defaults" ];
 | 
				
			||||||
 | 
					          };
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					          type = "partition";
 | 
				
			||||||
 | 
					          name = "NIX_CRYPT_ROOT";
 | 
				
			||||||
 | 
					          start = "1GiB";
 | 
				
			||||||
 | 
					          end = "100%";
 | 
				
			||||||
 | 
					          content = {
 | 
				
			||||||
 | 
					            type = "luks";
 | 
				
			||||||
 | 
					            name = "main";
 | 
				
			||||||
 | 
					            content = {
 | 
				
			||||||
 | 
					              type = "btrfs";
 | 
				
			||||||
 | 
					              name = "BTRFS_ROOT";
 | 
				
			||||||
 | 
					              mountpoint = "/";
 | 
				
			||||||
 | 
					              subvolumes = [ "/home" "/nixos" "/swap" ];
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					          };
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      ];
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,63 +0,0 @@
 | 
				
			||||||
#!/bin/sh
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
set -xe
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
settle() {
 | 
					 | 
				
			||||||
    udevadm trigger --subsystem-match=block
 | 
					 | 
				
			||||||
    udevadm settle
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
lsblk
 | 
					 | 
				
			||||||
echo 'Enter the name of the device to WIPE and install (something like "sda"):'
 | 
					 | 
				
			||||||
read DRIVE_ID
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo 'Enter a passphrase to encrypt the disk:'
 | 
					 | 
				
			||||||
read -s DRIVE_PASSPHRASE
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Creating partition table..."
 | 
					 | 
				
			||||||
parted -s "/dev/${DRIVE_ID}" -- mklabel gpt
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Creating EFI system partition..."
 | 
					 | 
				
			||||||
parted -s "/dev/${DRIVE_ID}" -- mkpart ESP 1MiB 1GiB
 | 
					 | 
				
			||||||
parted -s "/dev/${DRIVE_ID}" -- set 1 boot on
 | 
					 | 
				
			||||||
mkfs.fat -F32 "/dev/${DRIVE_ID}1" -n NIX_BOOT
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Creating encrypted root partition..."
 | 
					 | 
				
			||||||
parted -s "/dev/${DRIVE_ID}" -- mkpart luks 1GiB 100%
 | 
					 | 
				
			||||||
echo "$DRIVE_PASSPHRASE" | cryptsetup --batch-mode luksFormat --label CRYPT_ROOT "/dev/${DRIVE_ID}2"
 | 
					 | 
				
			||||||
settle
 | 
					 | 
				
			||||||
echo "$DRIVE_PASSPHRASE" | cryptsetup luksOpen /dev/disk/by-label/CRYPT_ROOT "crypt_root"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Creating btrfs partition..."
 | 
					 | 
				
			||||||
mkfs.btrfs --quiet --label NIX_ROOT /dev/mapper/"crypt_root"
 | 
					 | 
				
			||||||
MNTPOINT=$(mktemp -d)
 | 
					 | 
				
			||||||
mount /dev/mapper/"crypt_root" "$MNTPOINT"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Creating subvolumes..."
 | 
					 | 
				
			||||||
btrfs subvolume create "$MNTPOINT"/@nixos
 | 
					 | 
				
			||||||
btrfs subvolume create "$MNTPOINT"/@home
 | 
					 | 
				
			||||||
btrfs subvolume create "$MNTPOINT"/@swap
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Closing btrfs partition..."
 | 
					 | 
				
			||||||
umount -Rl "$MNTPOINT"
 | 
					 | 
				
			||||||
rm -rf "$MNTPOINT"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Mounting root btrfs submodule to '$MNTPOINT' ..."
 | 
					 | 
				
			||||||
MNTPOINT=$(mktemp -d)
 | 
					 | 
				
			||||||
mount /dev/disk/by-label/NIX_ROOT "$MNTPOINT" -o subvol=@nixos,noatime,compress=zstd
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Creating and mounting EFI system partition mountpoint..."
 | 
					 | 
				
			||||||
mkdir -p "$MNTPOINT/boot"
 | 
					 | 
				
			||||||
mount /dev/disk/by-label/NIX_BOOT "$MNTPOINT/boot"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Creating home partition mountpoint..."
 | 
					 | 
				
			||||||
mkdir -p "$MNTPOINT/home"
 | 
					 | 
				
			||||||
mount /dev/disk/by-label/NIX_ROOT "$MNTPOINT/home" -o subvol=@home,noatime,compress=zstd
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
echo "Swapfile"
 | 
					 | 
				
			||||||
mkdir -p "$MNTPOINT/swap"
 | 
					 | 
				
			||||||
mount /dev/disk/by-label/NIX_ROOT "$MNTPOINT/swap" -o subvol=@swap,noatime
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# echo "Installing system..."
 | 
					 | 
				
			||||||
nixos-generate-config --root "$MNTPOINT"
 | 
					 | 
				
			||||||
# nixos-install --root "$MNTPOINT"
 | 
					 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue