diff options
Diffstat (limited to 'modules/home')
| -rw-r--r-- | modules/home/dotfiles.nix | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/modules/home/dotfiles.nix b/modules/home/dotfiles.nix index 3df944c..21afb5e 100644 --- a/modules/home/dotfiles.nix +++ b/modules/home/dotfiles.nix | |||
| @@ -2,6 +2,15 @@ | |||
| 2 | let | 2 | let |
| 3 | cfg = config.home.dotfiles; | 3 | cfg = config.home.dotfiles; |
| 4 | dotfilesDir = "${config.home.homeDirectory}/dotfiles"; | 4 | dotfilesDir = "${config.home.homeDirectory}/dotfiles"; |
| 5 | |||
| 6 | # Packages in the external dotfiles repo that are only relevant on one | ||
| 7 | # platform. Kept minimal and overridable via excludePackages rather than | ||
| 8 | # a full per-platform mapping - see design.md for alternatives considered. | ||
| 9 | platformDefaultExcludes = | ||
| 10 | lib.optionals (!pkgs.stdenv.isDarwin) [ "iterm2" ] | ||
| 11 | ++ lib.optionals (!pkgs.stdenv.isLinux) [ "herbstluftwm" "xorg" ]; | ||
| 12 | |||
| 13 | excludePackages = platformDefaultExcludes ++ cfg.excludePackages; | ||
| 5 | in | 14 | in |
| 6 | { | 15 | { |
| 7 | options.home.dotfiles.repoUrl = lib.mkOption { | 16 | options.home.dotfiles.repoUrl = lib.mkOption { |
| @@ -10,11 +19,18 @@ in | |||
| 10 | description = "Git URL of the personal dotfiles repo to clone and stow into $HOME. Leave empty to disable."; | 19 | description = "Git URL of the personal dotfiles repo to clone and stow into $HOME. Leave empty to disable."; |
| 11 | }; | 20 | }; |
| 12 | 21 | ||
| 22 | options.home.dotfiles.excludePackages = lib.mkOption { | ||
| 23 | type = lib.types.listOf lib.types.str; | ||
| 24 | default = [ ]; | ||
| 25 | description = "Names of dotfiles stow packages to always skip, in addition to built-in platform defaults."; | ||
| 26 | }; | ||
| 27 | |||
| 13 | config = lib.mkIf (cfg.repoUrl != "") { | 28 | config = lib.mkIf (cfg.repoUrl != "") { |
| 14 | home.packages = [ pkgs.git pkgs.stow ]; | 29 | home.packages = [ pkgs.git pkgs.stow ]; |
| 15 | 30 | ||
| 16 | home.activation.dotfiles = lib.hm.dag.entryAfter [ "writeBoundary" ] '' | 31 | home.activation.dotfiles = lib.hm.dag.entryAfter [ "writeBoundary" ] '' |
| 17 | DOTFILES_DIR=${lib.escapeShellArg dotfilesDir} | 32 | DOTFILES_DIR=${lib.escapeShellArg dotfilesDir} |
| 33 | EXCLUDE_PACKAGES=(${lib.escapeShellArgs excludePackages}) | ||
| 18 | if [ ! -d "$DOTFILES_DIR/.git" ]; then | 34 | if [ ! -d "$DOTFILES_DIR/.git" ]; then |
| 19 | $DRY_RUN_CMD ${pkgs.git}/bin/git clone --recurse-submodules \ | 35 | $DRY_RUN_CMD ${pkgs.git}/bin/git clone --recurse-submodules \ |
| 20 | ${lib.escapeShellArg cfg.repoUrl} "$DOTFILES_DIR" | 36 | ${lib.escapeShellArg cfg.repoUrl} "$DOTFILES_DIR" |
| @@ -23,6 +39,17 @@ in | |||
| 23 | for pkg in "$DOTFILES_DIR"/*/; do | 39 | for pkg in "$DOTFILES_DIR"/*/; do |
| 24 | pkg_name="$(basename "$pkg")" | 40 | pkg_name="$(basename "$pkg")" |
| 25 | case "$pkg_name" in .*) continue ;; esac | 41 | case "$pkg_name" in .*) continue ;; esac |
| 42 | skip=false | ||
| 43 | for excluded in "''${EXCLUDE_PACKAGES[@]}"; do | ||
| 44 | if [ "$pkg_name" = "$excluded" ]; then | ||
| 45 | skip=true | ||
| 46 | break | ||
| 47 | fi | ||
| 48 | done | ||
| 49 | if [ "$skip" = true ]; then | ||
| 50 | echo "Skipping dotfiles package '$pkg_name' — not relevant on this platform." >&2 | ||
| 51 | continue | ||
| 52 | fi | ||
| 26 | $DRY_RUN_CMD ${pkgs.stow}/bin/stow -d "$DOTFILES_DIR" -t ${lib.escapeShellArg config.home.homeDirectory} "$pkg_name" \ | 53 | $DRY_RUN_CMD ${pkgs.stow}/bin/stow -d "$DOTFILES_DIR" -t ${lib.escapeShellArg config.home.homeDirectory} "$pkg_name" \ |
| 27 | || echo "Warning: stow failed for package '$pkg_name' — skipped." >&2 | 54 | || echo "Warning: stow failed for package '$pkg_name' — skipped." >&2 |
| 28 | done | 55 | done |
