Files
nixos/home/hooks.nix
2026-03-18 17:08:24 +00:00

103 lines
3.9 KiB
Nix

{ lib, pkgs, ... }:
{
home.activation = {
setupDotfiles = lib.hm.dag.entryAfter ["writeBoundary"] ''
if [[ -v DRY_RUN ]]; then
echo "Dry run: Would bootstrap dotfiles from labs.scarif.space"
exit
fi
TEMP_DIR=$(mktemp -d)
DOTFILES_DIR="$HOME/.config/dotfiles"
DOTFILES_GIT_DIR="$DOTFILES_DIR/.git"
if [ ! -d "$DOTFILES_GIT_DIR" ]; then
echo "No local repository so cloning from remote"
SOURCE="https://labs.scarif.space/chris/dotfiles.git"
${pkgs.git}/bin/git clone -b main "$SOURCE" "$TEMP_DIR"
mv "$TEMP_DIR/.git" "$DOTFILES_GIT_DIR"
else
echo "Local repository found so cloning from there"
${pkgs.git}/bin/git clone -b main "$DOTFILES_GIT_DIR" "$TEMP_DIR"
${pkgs.git}/bin/git --git-dir="$DOTFILES_GIT_DIR" --work-tree="$TEMP_DIR" pull --rebase || true
fi
echo "Copying dot files to home"
${pkgs.coreutils}/bin/cp -rfT "$TEMP_DIR" "$HOME"
NVIM_DIR="$HOME/.config/nvim"
echo "Neovim config not initialised so initialising from remote"
${pkgs.git}/bin/git --git-dir="$DOTFILES_GIT_DIR" --work-tree="$HOME" submodule set-url ".config/nvim" https://labs.scarif.space/chris/nvim.git
${pkgs.git}/bin/git --git-dir="$DOTFILES_GIT_DIR" --work-tree="$HOME" submodule update --init || true
${pkgs.git}/bin/git --git-dir="$DOTFILES_GIT_DIR" --work-tree="$HOME" submodule set-url ".config/nvim" git@labs.scarif.space:chris/nvim.git
cd "$HOME"
echo "Cleanup"
${pkgs.coreutils}/bin/rm -rf "$TEMP_DIR"
${pkgs.coreutils}/bin/rm -rf "$HOME/.git" || true
echo "Dotfiles bootstrapped successfully."
'';
setupDevDirectories = lib.hm.dag.entryAfter ["writeBoundary"] ''
if [[ -v DRY_RUN ]]; then
echo "Dry run: Would create dev directories"
exit
fi
echo "Creating development directories"
for dir in "DevOps" "FSharp" "JavaScript" "Scala" "Rust" "PHP" "Tutorials" "Sites" "MobileApps" "Tries"; do
if [ ! -d "$HOME/Code/$dir" ]; then
mkdir -p "$HOME/Code/$dir"
fi
done
'';
setupInitialConfigs = lib.hm.dag.entryAfter ["writeBoundary"] ''
if [[ -v DRY_RUN ]]; then
echo "Dry run: Would copy initial config files"
exit
fi
DEST_FILE="$HOME/.config/Nextcloud/nextcloud.cfg"
if [ ! -f "$DEST_FILE" ]; then
mkdir -p "$(dirname "$DEST_FILE")"
cp "${../initial-configs/nextcloud.cfg}" "$DEST_FILE"
fi
DEST_FILE="$HOME/.config/sinew.in/Enpass.conf"
if [ ! -f "$DEST_FILE" ]; then
mkdir -p "$(dirname "$DEST_FILE")"
cp "${../initial-configs/Enpass.conf}" "$DEST_FILE"
fi
DEST_FILE="$HOME/.config/obsidian/obsidian.json"
if [ ! -f "$DEST_FILE" ]; then
mkdir -p "$(dirname "$DEST_FILE")"
cp "${../initial-configs/obsidian.json}" "$DEST_FILE"
fi
'';
setupDefaultWallpaper = lib.hm.dag.entryAfter ["writeBoundary"] ''
if [[ -v DRY_RUN ]]; then
echo "Dry run: Would copy wallpaper and initialise colour scheme if not set"
exit
fi
WALLPAPER_FILE="$HOME/.config/station/current/background"
if [ ! -f "$WALLPAPER_FILE" ]; then
mkdir -p "$(dirname "$WALLPAPER_FILE")"
ln -nsf ${../default_wallpaper.png} "$WALLPAPER_FILE"
fi
if [ ! -f "$HOME/.config/wal/colors" ]; then
${pkgs.pywal16}/bin/wal -i "$WALLPAPER_FILE"
fi
'';
};
}