From 41db5fc767fbe5a5453b2fa0583de8c3b2cf4021 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Thu, 17 Sep 2026 11:49:58 +0200 Subject: Add automatic dotfiles clone + stow modules/home/dotfiles.nix clones ~/dotfiles on activation (only if not already present) and stows every top-level package directory into $HOME, independently per package so one conflict doesn't block the rest. Removes home-manager's own git config management in favor of letting the stowed ~/dotfiles/git/.gitconfig own it, and adds homeConfigurations."tom@darwin" so the feature is usable on this Mac. users/tom.nix now points home.dotfiles.repoUrl at the real repo. --- modules/home/cli-tools.nix | 1 + modules/home/default.nix | 2 +- modules/home/dotfiles.nix | 32 ++++++++++++++++++++++++++++++++ modules/home/git.nix | 9 --------- 4 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 modules/home/dotfiles.nix delete mode 100644 modules/home/git.nix (limited to 'modules/home') diff --git a/modules/home/cli-tools.nix b/modules/home/cli-tools.nix index c489e1c..aedbb40 100644 --- a/modules/home/cli-tools.nix +++ b/modules/home/cli-tools.nix @@ -1,6 +1,7 @@ { pkgs, ... }: { home.packages = with pkgs; [ + git ripgrep fd bat diff --git a/modules/home/default.nix b/modules/home/default.nix index 206a0ad..ec32c7f 100644 --- a/modules/home/default.nix +++ b/modules/home/default.nix @@ -1,8 +1,8 @@ { imports = [ - ./git.nix ./shell.nix ./editor.nix ./cli-tools.nix + ./dotfiles.nix ]; } diff --git a/modules/home/dotfiles.nix b/modules/home/dotfiles.nix new file mode 100644 index 0000000..3df944c --- /dev/null +++ b/modules/home/dotfiles.nix @@ -0,0 +1,32 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.home.dotfiles; + dotfilesDir = "${config.home.homeDirectory}/dotfiles"; +in +{ + options.home.dotfiles.repoUrl = lib.mkOption { + type = lib.types.str; + default = ""; + description = "Git URL of the personal dotfiles repo to clone and stow into $HOME. Leave empty to disable."; + }; + + config = lib.mkIf (cfg.repoUrl != "") { + home.packages = [ pkgs.git pkgs.stow ]; + + home.activation.dotfiles = lib.hm.dag.entryAfter [ "writeBoundary" ] '' + DOTFILES_DIR=${lib.escapeShellArg dotfilesDir} + if [ ! -d "$DOTFILES_DIR/.git" ]; then + $DRY_RUN_CMD ${pkgs.git}/bin/git clone --recurse-submodules \ + ${lib.escapeShellArg cfg.repoUrl} "$DOTFILES_DIR" + fi + if [ -d "$DOTFILES_DIR" ]; then + for pkg in "$DOTFILES_DIR"/*/; do + pkg_name="$(basename "$pkg")" + case "$pkg_name" in .*) continue ;; esac + $DRY_RUN_CMD ${pkgs.stow}/bin/stow -d "$DOTFILES_DIR" -t ${lib.escapeShellArg config.home.homeDirectory} "$pkg_name" \ + || echo "Warning: stow failed for package '$pkg_name' — skipped." >&2 + done + fi + ''; + }; +} diff --git a/modules/home/git.nix b/modules/home/git.nix deleted file mode 100644 index 4eab076..0000000 --- a/modules/home/git.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ - programs.git = { - enable = true; - extraConfig = { - init.defaultBranch = "main"; - pull.rebase = true; - }; - }; -} -- cgit v1.3