mirror of
https://github.com/nmasur/dotfiles
synced 2024-11-23 01:05:38 +00:00
create automatic partition installer
This commit is contained in:
parent
8d50690a79
commit
f4786156de
13
flake.nix
13
flake.nix
@ -48,8 +48,7 @@
|
|||||||
|
|
||||||
in {
|
in {
|
||||||
|
|
||||||
# Define my systems
|
# You can load it from any NixOS system with:
|
||||||
# You can load it from an empty system with:
|
|
||||||
# nix-shell -p nixFlakes
|
# nix-shell -p nixFlakes
|
||||||
# sudo nixos-rebuild switch --flake github:nmasur/dotfiles#desktop
|
# sudo nixos-rebuild switch --flake github:nmasur/dotfiles#desktop
|
||||||
nixosConfigurations = {
|
nixosConfigurations = {
|
||||||
@ -57,6 +56,16 @@
|
|||||||
import ./hosts/desktop { inherit nixpkgs home-manager nur globals; };
|
import ./hosts/desktop { inherit nixpkgs home-manager nur globals; };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# You can partition, format, and install with:
|
||||||
|
# nix-shell -p nixFlakes
|
||||||
|
# nix run github:nmasur/dotfiles#installer -- nvme0n1 desktop
|
||||||
|
# Will erase drives; use at your own risk!
|
||||||
|
apps = forAllSystems (system:
|
||||||
|
let pkgs = import nixpkgs { inherit system; };
|
||||||
|
in {
|
||||||
|
installer = import ./modules/system/installer.nix { inherit pkgs; };
|
||||||
|
});
|
||||||
|
|
||||||
# Used to run commands and edit files in this repo
|
# Used to run commands and edit files in this repo
|
||||||
devShells = forAllSystems (system:
|
devShells = forAllSystems (system:
|
||||||
let pkgs = import nixpkgs { inherit system; };
|
let pkgs = import nixpkgs { inherit system; };
|
||||||
|
38
modules/system/installer.nix
Normal file
38
modules/system/installer.nix
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
{ pkgs, ... }: {
|
||||||
|
|
||||||
|
# Inspired by https://github.com/cleverca22/nix-tests/blob/master/kexec/justdoit.nix
|
||||||
|
# This will partition and format drives; use at your own risk.
|
||||||
|
|
||||||
|
type = "app";
|
||||||
|
|
||||||
|
program = pkgs.writeShellScriptBin "installer" ''
|
||||||
|
#!${pkgs.stdenv.shell}
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
DISK=$1
|
||||||
|
FLAKE=$2
|
||||||
|
|
||||||
|
if [ -z "$DISK" ] || [ -z "$FLAKE" ]; then
|
||||||
|
echo "Missing required parameter."
|
||||||
|
echo "Usage: installer -- <disk> <host>"
|
||||||
|
echo "Example: installer -- nvme0n1 desktop"
|
||||||
|
echo "Flake example: nix run github:nmasur/dotfiles#installer -- nvme0n1 desktop"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
parted /dev/''${DISK} -- mklabel gpt
|
||||||
|
parted /dev/''${DISK} -- mkpart primary 512MiB 100%
|
||||||
|
parted /dev/''${DISK} -- mkpart ESP fat32 1MiB 512MiB
|
||||||
|
parted /dev/''${DISK} -- set 3 esp on
|
||||||
|
mkfs.ext4 -L nixos /dev/''${DISK}p1
|
||||||
|
mkfs.fat -F 32 -n boot /dev/''${DISK}p2
|
||||||
|
|
||||||
|
mount /dev/disk/by-label/nixos /mnt
|
||||||
|
mkdir --parents /mnt/boot
|
||||||
|
mount /dev/disk/by-label/boot /mnt/boot
|
||||||
|
|
||||||
|
nixos-install --flake github:nmasur/dotfiles#''${FLAKE}
|
||||||
|
'';
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user