Skip to content

Commit 40e87b4

Browse files
committed
Restructure: Move darwin and vagrant into hosts directory
1 parent 185a996 commit 40e87b4

File tree

16 files changed

+1098
-102
lines changed

16 files changed

+1098
-102
lines changed

flake.nix

Lines changed: 95 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,31 @@
33

44
inputs = {
55
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
6-
nix-darwin.url = "github:LnL7/nix-darwin";
7-
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
6+
nix-darwin = {
7+
url = "github:LnL7/nix-darwin";
8+
inputs.nixpkgs.follows = "nixpkgs";
9+
};
810
nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew";
911

1012
# Linux-specific inputs
11-
home-manager.url = "github:nix-community/home-manager";
12-
home-manager.inputs.nixpkgs.follows = "nixpkgs";
13+
home-manager = {
14+
url = "github:nix-community/home-manager";
15+
inputs.nixpkgs.follows = "nixpkgs";
16+
};
1317
};
1418

1519
outputs = inputs@{ self, nix-darwin, nixpkgs, nix-homebrew, home-manager }:
1620
let
21+
# Overlays
22+
overlays = [
23+
(import ./overlays/tfenv.nix)
24+
(import ./overlays/nvm.nix)
25+
(import ./overlays/browser-forward.nix)
26+
];
27+
28+
# Create a version of nixpkgs with our overlays for Linux
29+
nixpkgsWithOverlays = system: import nixpkgs { inherit system overlays; };
30+
1731
# Default macOS configuration
1832
darwinSystem = { hostname ? "macbook", # Generic default hostname
1933
username ? "user", # Generic default username
@@ -33,73 +47,60 @@
3347
# Add Home Manager to Darwin
3448
home-manager.darwinModules.home-manager
3549
{
36-
home-manager.useGlobalPkgs = true;
37-
home-manager.useUserPackages = true;
38-
home-manager.extraSpecialArgs = { inherit username; };
39-
# Add backup file extension to avoid conflicts
40-
home-manager.backupFileExtension = "backup";
41-
42-
# Inline Home Manager configuration
43-
home-manager.users.${username} = { config, lib, pkgs, ... }:
44-
let sharedZsh = import ./common/zsh/shared.nix;
45-
in {
46-
home.username = username;
47-
home.homeDirectory = "/Users/${username}";
48-
home.stateVersion = "23.11";
49-
50-
programs.zsh = {
51-
enable = true;
52-
53-
oh-my-zsh = {
54-
enable = true;
55-
plugins = [ "git" ];
56-
theme = "";
50+
home-manager = {
51+
useGlobalPkgs = true;
52+
useUserPackages = true;
53+
extraSpecialArgs = { inherit username; };
54+
backupFileExtension = "backup";
55+
56+
# Inline Home Manager configuration
57+
users.${username} = { config, lib, pkgs, ... }:
58+
let sharedZsh = import ./common/zsh/shared.nix;
59+
in {
60+
home = {
61+
username = username;
62+
homeDirectory = "/Users/${username}";
63+
stateVersion = "23.11";
5764
};
5865

59-
shellAliases = sharedZsh.aliases // {
60-
nixswitch =
61-
"darwin-rebuild switch --flake ~/.config/nix#${hostname}";
66+
programs.zsh = {
67+
enable = true;
68+
69+
oh-my-zsh = {
70+
enable = true;
71+
plugins = [ "git" ];
72+
theme = "";
73+
};
74+
75+
shellAliases = sharedZsh.aliases // {
76+
nixswitch =
77+
"darwin-rebuild switch --flake ~/.config/nix#${hostname}";
78+
};
79+
80+
initContent = ''
81+
# Source common settings
82+
${sharedZsh.options}
83+
${sharedZsh.keybindings}
84+
${sharedZsh.tools}
85+
86+
# Ensure Oh My Posh is properly initialized
87+
if command -v oh-my-posh &> /dev/null; then
88+
eval "$(oh-my-posh --init --shell zsh --config ~/.config/oh-my-posh/default.omp.json)"
89+
fi
90+
'';
6291
};
6392

64-
initContent = ''
65-
# Source common settings
66-
${sharedZsh.options}
67-
${sharedZsh.keybindings}
68-
${sharedZsh.tools}
69-
70-
# Ensure Oh My Posh is properly initialized
71-
if command -v oh-my-posh &> /dev/null; then
72-
eval "$(oh-my-posh --init --shell zsh --config ~/.config/oh-my-posh/default.omp.json)"
73-
fi
74-
'';
93+
home.file.".config/oh-my-posh/default.omp.json".source =
94+
./common/zsh/default.omp.json;
7595
};
76-
77-
home.file.".config/oh-my-posh/default.omp.json".source =
78-
./common/zsh/default.omp.json;
79-
};
96+
};
8097
}
8198
] ++ extraModules;
82-
specialArgs = {
83-
inherit inputs self hostname;
84-
username = username;
85-
};
86-
};
8799

88-
# Overlays
89-
overlays = [
90-
(import ./overlays/tfenv.nix)
91-
(import ./overlays/nvm.nix)
92-
(import ./overlays/browser-forward.nix)
93-
];
94-
95-
# Create a version of nixpkgs with our overlays for Linux
96-
nixpkgsWithOverlays = system:
97-
import nixpkgs {
98-
inherit system;
99-
inherit overlays;
100+
specialArgs = { inherit inputs self hostname username; };
100101
};
101102
in {
102-
# Generic macOS configuration - can be customized with hostname and user
103+
# macOS configurations
103104
darwinConfigurations = {
104105
"macbook" = darwinSystem {
105106
hostname = "macbook";
@@ -113,44 +114,39 @@
113114
};
114115

115116
# Standalone home-manager configuration for Vagrant VM
116-
# Install with:
117-
# $ nix run home-manager/master -- switch --flake ~/.config/nix#vagrant
118-
homeConfigurations = {
119-
"vagrant" = home-manager.lib.homeManagerConfiguration {
120-
pkgs = nixpkgsWithOverlays "aarch64-linux";
121-
modules = [
122-
./vagrant/home.nix
123-
{
124-
home = {
125-
username = "vagrant";
126-
homeDirectory = "/home/vagrant";
127-
stateVersion = "23.11";
128-
};
129-
nixpkgs.config.allowUnfree = true;
130-
131-
# Explicitly specify nix.package for home-manager
132-
nix = {
133-
package = nixpkgs.legacyPackages.aarch64-linux.nix;
134-
settings = {
135-
experimental-features = [ "nix-command" "flakes" ];
136-
};
137-
};
138-
139-
programs.fish = { enable = false; };
140-
141-
nixpkgs.overlays = [
142-
(final: prev: {
143-
# Override fish package properly inside the module
144-
fish = prev.fish.overrideAttrs (oldAttrs: {
145-
doCheck = false;
146-
doInstallCheck = false;
147-
});
148-
})
149-
];
150-
}
151-
];
152-
extraSpecialArgs = { username = "vagrant"; };
153-
};
117+
homeConfigurations.vagrant = home-manager.lib.homeManagerConfiguration {
118+
pkgs = nixpkgsWithOverlays "aarch64-linux";
119+
modules = [
120+
./vagrant/home.nix
121+
{
122+
home = {
123+
username = "vagrant";
124+
homeDirectory = "/home/vagrant";
125+
stateVersion = "23.11";
126+
};
127+
128+
nixpkgs.config.allowUnfree = true;
129+
130+
# Explicitly specify nix.package for home-manager
131+
nix = {
132+
package = nixpkgs.legacyPackages.aarch64-linux.nix;
133+
settings.experimental-features = [ "nix-command" "flakes" ];
134+
};
135+
136+
programs.fish.enable = false;
137+
138+
nixpkgs.overlays = [
139+
(final: prev: {
140+
# Override fish package properly inside the module
141+
fish = prev.fish.overrideAttrs (oldAttrs: {
142+
doCheck = false;
143+
doInstallCheck = false;
144+
});
145+
})
146+
];
147+
}
148+
];
149+
extraSpecialArgs = { username = "vagrant"; };
154150
};
155151
};
156152
}

hosts/darwin/default.nix

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{ config, pkgs, lib, username, hostname, ... }:
2+
3+
{
4+
imports = [ ./homebrew.nix ./defaults.nix ./dock.nix ./git.nix ];
5+
6+
# macOS specific packages
7+
environment.systemPackages = with pkgs; [
8+
oh-my-posh
9+
eza
10+
zoxide
11+
hstr
12+
git
13+
diff-so-fancy
14+
nixfmt-classic
15+
tree
16+
];
17+
18+
programs.zsh.enable = true;
19+
20+
system.configurationRevision = lib.mkIf (builtins ? currentSystem) null;
21+
22+
system.stateVersion = 5;
23+
24+
ids.gids.nixbld = 30000;
25+
26+
# System activation scripts
27+
system.activationScripts = {
28+
applications.text = let
29+
env = pkgs.buildEnv {
30+
name = "system-applications";
31+
paths = config.environment.systemPackages;
32+
pathsToLink = "/Applications";
33+
};
34+
in lib.mkForce ''
35+
# Set up applications.
36+
echo "setting up /Applications..." >&2
37+
rm -rf /Applications/Nix\ Apps
38+
mkdir -p /Applications/Nix\ Apps
39+
find ${env}/Applications -maxdepth 1 -type l -exec readlink '{}' + |
40+
while read -r src; do
41+
app_name=$(basename "$src")
42+
echo "copying $src" >&2
43+
${pkgs.mkalias}/bin/mkalias "$src" "/Applications/Nix Apps/$app_name"
44+
done
45+
'';
46+
47+
postActivation.text = lib.mkAfter ''
48+
echo "==== Starting Homebrew Updates ====" >&2
49+
50+
# Run Homebrew commands as the user with proper environment setup and send output to stderr
51+
echo "Running brew update..." >&2
52+
su ${username} -c '/opt/homebrew/bin/brew update' >&2
53+
54+
echo "Running brew upgrade --cask --greedy..." >&2
55+
su ${username} -c '/opt/homebrew/bin/brew upgrade --cask --greedy' >&2
56+
57+
# Dock configuration is now handled in dock.nix
58+
59+
echo "==== Homebrew update completed ====" >&2
60+
'';
61+
};
62+
63+
# SSH configuration
64+
environment.etc."user-ssh-config".source = pkgs.writeText "ssh-config" ''
65+
Host *
66+
AddKeysToAgent yes
67+
IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock"
68+
Protocol 2
69+
Compression yes
70+
ServerAliveInterval 20
71+
ServerAliveCountMax 10
72+
TCPKeepAlive yes
73+
Host nix-dev
74+
HostName 127.0.0.1
75+
User vagrant
76+
Port 2222
77+
UserKnownHostsFile /dev/null
78+
StrictHostKeyChecking no
79+
PasswordAuthentication no
80+
IdentityFile /Users/${username}/.config/nix/.vagrant/machines/default/utm/private_key
81+
IdentitiesOnly yes
82+
LogLevel FATAL
83+
ForwardAgent yes
84+
PubkeyAcceptedKeyTypes +ssh-rsa
85+
HostKeyAlgorithms +ssh-rsa
86+
87+
'';
88+
89+
system.activationScripts.userSshConfig.text = ''
90+
mkdir -p /Users/${username}/.ssh
91+
cp ${
92+
config.environment.etc."user-ssh-config".source
93+
} /Users/${username}/.ssh/config
94+
chown ${username}:staff /Users/${username}/.ssh/config
95+
chmod 600 /Users/${username}/.ssh/config
96+
'';
97+
98+
security.pam.services.sudo_local.touchIdAuth = true;
99+
100+
nixpkgs.hostPlatform = "aarch64-darwin";
101+
102+
networking.hostName = hostname;
103+
104+
users.users.${username} = {
105+
description = "${username}";
106+
shell = pkgs.zsh;
107+
home = "/Users/${username}";
108+
};
109+
}

hosts/darwin/defaults.nix

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{ config, pkgs, username, ... }:
2+
3+
{
4+
system.defaults = {
5+
finder.FXPreferredViewStyle = "clmv";
6+
loginwindow.GuestEnabled = false;
7+
8+
screencapture.location = "/Users/${username}/Desktop/screenshots";
9+
10+
NSGlobalDomain = {
11+
AppleShowAllExtensions = true;
12+
ApplePressAndHoldEnabled = false;
13+
KeyRepeat = 2;
14+
InitialKeyRepeat = 15;
15+
"com.apple.mouse.tapBehavior" = 1;
16+
"com.apple.sound.beep.volume" = 0.0;
17+
"com.apple.sound.beep.feedback" = 0;
18+
};
19+
20+
dock = {
21+
autohide = true;
22+
show-recents = false;
23+
launchanim = true;
24+
orientation = "bottom";
25+
tilesize = 32;
26+
magnification = true;
27+
largesize = 48;
28+
mru-spaces = false;
29+
static-only = false;
30+
wvous-tr-corner = 2; # Top Right - Mission Control
31+
wvous-bl-corner = 13; # Bottom Left - Lock Screen
32+
};
33+
34+
finder = {
35+
_FXShowPosixPathInTitle = false;
36+
AppleShowAllFiles = true;
37+
CreateDesktop = true;
38+
ShowPathbar = true;
39+
ShowStatusBar = true;
40+
};
41+
42+
trackpad = {
43+
Clicking = false;
44+
TrackpadThreeFingerDrag = true;
45+
};
46+
47+
WindowManager.EnableStandardClickToShowDesktop = false;
48+
};
49+
}

0 commit comments

Comments
 (0)