mirror of
https://github.com/librephoenix/nixos-config
synced 2025-01-18 22:55:52 +05:30
48 lines
1.8 KiB
Bash
Executable file
48 lines
1.8 KiB
Bash
Executable file
#!/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 )
|
|
if [ -z "$1" ]
|
|
then
|
|
SCRIPT_DIR=$1
|
|
else
|
|
SCRIPT_DIR=~/.dotfiles
|
|
fi
|
|
nix-shell -p git --command "git clone https://gitlab.com/librephoenix/nixos-config $SCRIPT_DIR"
|
|
|
|
# Generate hardware config for new system
|
|
sudo nixos-generate-config --show-hardware-config > $SCRIPT_DIR/system/hardware-configuration.nix
|
|
|
|
# Check if uefi or bios
|
|
if [ -d /sys/firmware/efi/efivars ]; then
|
|
sed -i "0,/bootMode.*=.*\".*\";/s//bootMode = \"uefi\";/" $SCRIPT_DIR/flake.nix
|
|
else
|
|
sed -i "0,/bootMode.*=.*\".*\";/s//bootMode = \"bios\";/" $SCRIPT_DIR/flake.nix
|
|
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\";/" $SCRIPT_DIR/flake.nix
|
|
fi
|
|
|
|
# Patch flake.nix with different username/name and remove email by default
|
|
sed -i "0,/emmet/s//$(whoami)/" $SCRIPT_DIR/flake.nix
|
|
sed -i "0,/Emmet/s//$(getent passwd $(whoami) | cut -d ':' -f 5 | cut -d ',' -f 1)/" $SCRIPT_DIR/flake.nix
|
|
sed -i "s/emmet@librephoenix.com//" $SCRIPT_DIR/flake.nix
|
|
sed -i "s+~/.dotfiles+$SCRIPT_DIR+g" $SCRIPT_DIR/flake.nix
|
|
|
|
# Open up editor to manually edit flake.nix before install
|
|
if [ -z "$EDITOR" ]; then
|
|
EDITOR=nano;
|
|
fi
|
|
$EDITOR $SCRIPT_DIR/flake.nix;
|
|
|
|
# Permissions for files that should be owned by root
|
|
sudo $SCRIPT_DIR/harden.sh $SCRIPT_DIR;
|
|
|
|
# Rebuild system
|
|
sudo nixos-rebuild switch --flake $SCRIPT_DIR#system;
|
|
|
|
# Install and build home-manager configuration
|
|
nix run home-manager/master --extra-experimental-features nix-command --extra-experimental-features flakes -- switch --flake $SCRIPT_DIR#user;
|