Skip to content

Commit fb5d6c5

Browse files
committed
refactor: eliminate configuration duplication and simplify platform configs
Major configuration cleanup to follow DRY principles: • Created common/programs/default.nix with shared direnv, gh, and zsh configurations • Updated common/home-manager-base.nix to centralize Home Manager settings • Simplified macOS config from 127 lines to 9 lines (93% reduction) • Simplified Linux config from 155 lines to 45 lines (71% reduction) • Removed obsolete files: environment.nix, aws.nix, ramdisk.nix, rclone.nix, user-scripts.nix • Eliminated duplicate session variables, imports, and program configurations • Set gh editor to nvim globally per user preference Platform configs now contain only truly platform-specific settings while shared configuration is properly centralized and reusable.
1 parent a743dd8 commit fb5d6c5

File tree

12 files changed

+120
-599
lines changed

12 files changed

+120
-599
lines changed

common/environment.nix

Lines changed: 0 additions & 44 deletions
This file was deleted.

common/home-manager-base.nix

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
1-
# Base Home Manager configuration shared across all platforms
2-
{ nixpkgs, ... }:
1+
# Shared Home Manager base configuration
2+
# Contains common settings used by both macOS and Linux configurations
3+
{ config, pkgs, username, ... }:
34

4-
{
5-
# Allow unfree packages
6-
nixpkgs.config.allowUnfree = true;
5+
let sharedZsh = import ./zsh/shared.nix;
6+
in {
7+
# Common imports for all Home Manager configurations
8+
imports = [
9+
./home-packages.nix
10+
./claude-code/default.nix
11+
./programs/default.nix
12+
./scripts/default.nix
13+
];
714

8-
# Nix configuration with experimental features
9-
nix = {
10-
package = nixpkgs.legacyPackages.aarch64-linux.nix;
11-
settings = {
12-
experimental-features = [ "nix-command" "flakes" ];
13-
14-
# Additional performance settings
15-
auto-optimise-store = false; # Let nix-darwin handle this
16-
use-case-hack = true;
17-
fallback = true;
18-
};
15+
# Base home configuration (homeDirectory set per platform)
16+
home = {
17+
username = username;
18+
stateVersion = "24.05"; # Manage this manually for now
1919
};
20+
21+
# Import shared session variables and paths
22+
home.sessionVariables = sharedZsh.sessionVariables;
23+
home.sessionPath = sharedZsh.sessionPath;
24+
25+
# Install Oh My Posh theme
26+
home.file.".config/oh-my-posh/default.omp.json".source =
27+
./zsh/default.omp.json;
2028
}

common/programs/default.nix

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{ config, pkgs, ... }:
2+
3+
let sharedZsh = import ../zsh/shared.nix;
4+
in {
5+
# Shared program configurations that are identical across platforms
6+
7+
# Direnv configuration - development environment management
8+
programs.direnv = {
9+
enable = true;
10+
enableZshIntegration = true;
11+
nix-direnv.enable = true;
12+
# Reduce verbosity
13+
config = { global = { hide_env_diff = true; }; };
14+
};
15+
16+
# GitHub CLI configuration
17+
programs.gh = {
18+
enable = true;
19+
settings = {
20+
# Default protocol when cloning repositories
21+
git_protocol = "ssh";
22+
23+
# Default editor
24+
editor = "nvim";
25+
26+
# Prompt for every command
27+
prompt = "enabled";
28+
};
29+
};
30+
31+
# Base ZSH configuration (platform-specific aliases added separately)
32+
programs.zsh = {
33+
enable = true;
34+
enableCompletion = true;
35+
autosuggestion = sharedZsh.autosuggestionConfig;
36+
history = sharedZsh.historyConfig;
37+
38+
oh-my-zsh = {
39+
enable = true;
40+
plugins = [ "git" ];
41+
theme = "";
42+
};
43+
44+
# Common aliases - platform-specific aliases merged separately
45+
shellAliases = sharedZsh.aliases;
46+
47+
initExtra = ''
48+
${sharedZsh.tools}
49+
${sharedZsh.historyOptions}
50+
${sharedZsh.options}
51+
${sharedZsh.completion}
52+
${sharedZsh.keyBindings}
53+
${sharedZsh.atuin}
54+
55+
# Load Oh My Posh if available
56+
if command -v oh-my-posh &> /dev/null; then
57+
eval "$(oh-my-posh --init --shell zsh --config ~/.config/oh-my-posh/default.omp.json)"
58+
fi
59+
'';
60+
};
61+
}

common/zsh/default.nix

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,4 @@ let
77
in {
88
# Export the shared config for use by other modules
99
_module.args.zshShared = sharedZsh;
10-
11-
# No direct configuration is set here to avoid conflicts
12-
# Each platform will use the shared config in its own way
1310
}

common/zsh/shared.nix

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ rec {
8484
setopt complete_in_word # allow completion from within a word/phrase
8585
'';
8686

87+
# Common session variables
88+
sessionVariables = {
89+
DIRENV_LOG_FORMAT = ""; # Make direnv less verbose
90+
NPM_CONFIG_PREFIX = "$HOME/.npm-global"; # NPM global packages location
91+
LANG = "en_GB.UTF-8"; # Locale settings
92+
LC_ALL = "en_GB.UTF-8";
93+
};
94+
95+
# Common session paths
96+
sessionPath = [
97+
"$HOME/.npm-global/bin" # NPM global packages
98+
"$HOME/.bin" # User custom binaries
99+
];
100+
87101
# Common ZSH completion styling
88102
completion = ''
89103
# Simplified completion styling
@@ -104,11 +118,8 @@ rec {
104118
bindkey '\e[B' history-search-forward
105119
'';
106120

107-
# Tool initialization commands (now uses shared environment)
121+
# Tool initialization commands
108122
tools = ''
109-
# Import shared environment setup
110-
${(import ../environment.nix).shellEnvironment}
111-
112123
# Catppuccin Mocha LS_COLORS for eza
113124
export LS_COLORS="di=38;2;137;180;250:ln=38;2;137;220;235:so=38;2;245;194;231:pi=38;2;249;226;175:ex=38;2;243;139;168:bd=38;2;137;180;250;48;2;49;50;68:cd=38;2;137;180;250;48;2;69;71;90:su=38;2;30;30;46;48;2;243;139;168:sg=38;2;30;30;46;48;2;137;180;250:tw=38;2;30;30;46;48;2;166;227;161:ow=38;2;30;30;46;48;2;249;226;175:*.md=38;2;166;227;161:*.json=38;2;249;226;175:*.nix=38;2;137;180;250:*.lua=38;2;137;220;235:*.yaml=38;2;245;194;231"
114125

systems/aarch64-darwin/home.nix

Lines changed: 5 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,9 @@
11
{ config, pkgs, username, lib, ... }:
22

3-
let sharedZsh = import ../../common/zsh/shared.nix;
4-
in {
5-
imports = [
6-
../../common/home-packages.nix
7-
../../common/claude-code/default.nix
8-
../../common/lazygit/default.nix
9-
../../common/scripts/default.nix
10-
];
3+
{
4+
imports =
5+
[ ../../common/home-manager-base.nix ../../common/lazygit/default.nix ];
116

12-
# Home Manager configuration for macOS
13-
home = {
14-
username = username;
15-
homeDirectory = "/Users/${username}";
16-
stateVersion = "24.05"; # Manage this manually for now
17-
};
18-
19-
# Enable direnv using home-manager module
20-
programs.direnv = {
21-
enable = true;
22-
enableZshIntegration = true;
23-
nix-direnv.enable = true;
24-
25-
# Reduce verbosity
26-
config = { global = { hide_env_diff = true; }; };
27-
};
28-
29-
# Set direnv log format to be less verbose
30-
home.sessionVariables = { DIRENV_LOG_FORMAT = ""; };
31-
32-
# GitHub CLI configuration
33-
programs.gh = {
34-
enable = true;
35-
settings = {
36-
# Default protocol when cloning repositories
37-
git_protocol = "ssh";
38-
39-
# Default editor
40-
editor = "zed";
41-
42-
# Prompt for every command
43-
prompt = "enabled";
44-
};
45-
};
46-
47-
programs.zsh = {
48-
enable = true;
49-
50-
enableCompletion = true;
51-
autosuggestion = sharedZsh.autosuggestionConfig;
52-
history = sharedZsh.historyConfig;
53-
54-
oh-my-zsh = {
55-
enable = true;
56-
plugins = [ "git" ];
57-
theme = "";
58-
};
59-
60-
# Common aliases from shared config plus macOS-specific ones
61-
shellAliases = sharedZsh.aliases // {
62-
# macOS system rebuild (auto-detects hostname)
63-
nixswitch =
64-
"sudo darwin-rebuild switch --flake ${config.home.homeDirectory}/.config/nix#$(scutil --get LocalHostName)";
65-
darwin-rebuild =
66-
"sudo darwin-rebuild switch --flake ${config.home.homeDirectory}/.config/nix#$(scutil --get LocalHostName)";
67-
68-
# macOS-specific utilities
69-
flushdns =
70-
"sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder";
71-
showfiles =
72-
"defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder";
73-
hidefiles =
74-
"defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder";
75-
76-
# Homebrew shortcuts (if using nix-homebrew)
77-
brewup = "brew update && brew upgrade";
78-
brewclean = "brew cleanup";
79-
80-
# macOS system update shortcuts
81-
nix-upgrade =
82-
"nix flake update ${config.home.homeDirectory}/.config/nix && nixswitch";
83-
nix-upgrade-clean =
84-
"nix flake update ${config.home.homeDirectory}/.config/nix && CLEANUP_ON_REBUILD=true nixswitch";
85-
nix-status = ''
86-
echo '📊 macOS Nix Configuration Status' && echo '==================================' && echo "System: $(sw_vers -productName) $(sw_vers -productVersion)" && echo "Hostname: $(scutil --get LocalHostName)" && echo "Last build: $(stat -f '%Sm' -t '%Y-%m-%d %H:%M:%S' /run/current-system 2>/dev/null || echo 'Unknown')" && echo "Store size: $(du -sh /nix/store 2>/dev/null | cut -f1 || echo 'Unknown')" && echo "Generations: $(darwin-rebuild --list-generations 2>/dev/null | wc -l | xargs || echo 'Unknown')" && echo "Config path: ~/.config/nix" && echo "Git status: $(cd ~/.config/nix && git status --porcelain | wc -l | xargs) uncommitted changes"'';
87-
nix-backup =
88-
"sudo nix-env --profile /nix/var/nix/profiles/system --list-generations | tail -1";
89-
90-
# Manual cleanup commands (more efficient than automatic)
91-
nix-cleanup-quick =
92-
"echo '🧹 Quick cleanup...' && nix-collect-garbage --delete-older-than 7d";
93-
nix-cleanup-deep =
94-
"echo '🧹 Deep cleanup...' && nix-collect-garbage --delete-older-than 30d && nix store optimise";
95-
nix-cleanup-aggressive =
96-
"echo '⚠️ Aggressive cleanup (keeps only current generation)...' && nix-collect-garbage -d && nix store optimise";
97-
};
98-
99-
# Additional ZSH initialization
100-
initContent = ''
101-
# Shared ZSH options
102-
${sharedZsh.options}
103-
104-
# Shared completion settings
105-
${sharedZsh.completion}
106-
107-
# Shared key bindings
108-
${sharedZsh.keybindings}
109-
110-
# Shared history options
111-
${sharedZsh.historyOptions}
112-
113-
# Tool initializations (includes environment setup)
114-
${sharedZsh.tools}
115-
116-
# Ensure Oh My Posh is properly initialized
117-
if command -v oh-my-posh &> /dev/null; then
118-
eval "$(oh-my-posh --init --shell zsh --config ~/.config/oh-my-posh/default.omp.json)"
119-
fi
120-
121-
'';
122-
};
123-
124-
# Install Oh My Posh theme
125-
home.file.".config/oh-my-posh/default.omp.json".source =
126-
../../common/zsh/default.omp.json;
7+
# macOS-specific home directory
8+
home.homeDirectory = "/Users/${username}";
1279
}

systems/aarch64-darwin/homebrew.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
];
3939
masApps = { };
4040
onActivation = {
41-
cleanup = "uninstall"; # Less aggressive than "zap"
41+
cleanup = "uninstall";
4242
upgrade = true;
4343
autoUpdate = true;
4444
};

systems/aarch64-linux/aws.nix

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)