nixos-config/install.sh

42 lines
1.7 KiB
Bash
Raw Normal View History

#!/bin/sh
# Automated script to install my dotfiles
# Clone dotfiles
# TODO make ~/.dotfiles path arbitrary and make all other scripts conform to this
# using SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
2024-02-26 00:34:02 +05:30
nix-shell -p git --command "git clone https://gitlab.com/librephoenix/nixos-config ~/.dotfiles"
# Generate hardware config for new system
2024-02-26 00:34:02 +05:30
sudo nixos-generate-config --show-hardware-config > ~/.dotfiles/system/hardware-configuration.nix
# Check if uefi or bios
if [ -d /sys/firmware/efi/efivars ]; then
sed -i "0,/bootMode.*=.*\".*\";/s//bootMode = \"uefi\";/" ~/.dotfiles/flake.nix
else
sed -i "0,/bootMode.*=.*\".*\";/s//bootMode = \"bios\";/" ~/.dotfiles/flake.nix
2024-03-01 08:18:15 +05:30
grubDevice=$(findmnt / | awk -F' ' '{ print $2 }' | sed 's/\[.*\]//g' | tail -n 1 | lsblk -no pkname | tail -n 1 )
sed -i "0,/grubDevice.*=.*\".*\";/s//grubDevice = \"\/dev\/$grubDevice\";/" ~/.dotfiles/flake.nix
fi
# Patch flake.nix with different username/name and remove email by default
2024-02-27 08:05:27 +05:30
sed -i "0,/emmet/s//$(whoami)/" ~/.dotfiles/flake.nix
sed -i "0,/Emmet/s//$(getent passwd $(whoami) | cut -d ':' -f 5 | cut -d ',' -f 1)/" ~/.dotfiles/flake.nix
sed -i "s/emmet@librephoenix.com//" ~/.dotfiles/flake.nix
# Open up editor to manually edit flake.nix before install
2024-02-26 00:34:02 +05:30
if [ -z "$EDITOR" ]; then
EDITOR=nano;
fi
$EDITOR ~/.dotfiles/flake.nix;
# Permissions for files that should be owned by root
sudo ~/.dotfiles/harden.sh ~/.dotfiles;
# Rebuild system
2024-02-26 00:34:02 +05:30
sudo nixos-rebuild switch --flake ~/.dotfiles#system;
# Install and build home-manager configuration
nix run home-manager/master --extra-experimental-features nix-command --extra-experimental-features flakes -- switch --flake ~/.dotfiles#user;