-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
125 lines (117 loc) · 4.78 KB
/
flake.nix
File metadata and controls
125 lines (117 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{
description = "ibuki's NixOS + Hyprland rice (Modus Vivendi) + M1 Mac home-manager";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-darwin = {
url = "github:nix-darwin/nix-darwin";
inputs.nixpkgs.follows = "nixpkgs";
};
# Declaratively installs & manages Homebrew itself (for GUI app casks).
nix-homebrew.url = "github:zhaofengli/nix-homebrew";
};
outputs = { self, nixpkgs, home-manager, nix-darwin, nix-homebrew, ... }@inputs:
let
# The NixOS box is x86_64-linux; the Mac is aarch64-darwin. devShell and
# formatter are exposed for both (CI runs the x86_64-linux one).
linuxSystem = "x86_64-linux";
darwinSystem = "aarch64-darwin";
forAllSystems = nixpkgs.lib.genAttrs [ linuxSystem darwinSystem ];
# Both Macs (personal `ibuki`, work `yoshida`) build from the same
# modules — only the username/home dir differ. `mkDarwin` threads the
# username through to darwin/configuration.nix and home/darwin.nix so
# nothing is hardcoded. Apply with: darwin-rebuild switch --flake ~/dotfiles#<username>
mkDarwin = username: nix-darwin.lib.darwinSystem {
specialArgs = { inherit inputs username; };
modules = [
./darwin/configuration.nix
nix-homebrew.darwinModules.nix-homebrew
{
nix-homebrew = {
enable = true;
user = username; # owns the /opt/homebrew prefix
enableRosetta = false; # all our casks have native arm64 builds
autoMigrate = true; # adopt a pre-existing brew install if found
};
}
home-manager.darwinModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.backupFileExtension = "hm-bak";
home-manager.users.${username} = import ./home/darwin.nix;
home-manager.extraSpecialArgs = { inherit inputs username; };
}
];
};
# Standalone home-manager (no-sudo, user-only) for either Mac username.
# Apply with: home-manager switch --flake ~/dotfiles#<username>@mac
mkDarwinHome = username: home-manager.lib.homeManagerConfiguration {
pkgs = import nixpkgs {
system = darwinSystem;
config.allowUnfree = true;
};
extraSpecialArgs = { inherit inputs username; };
modules = [ ./home/darwin.nix ];
};
in
{
# ---------- NixOS host (system + user via HM module) ----------
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
system = linuxSystem;
specialArgs = { inherit inputs; };
modules = [
./nixos/configuration.nix
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.backupFileExtension = "hm-bak";
home-manager.users.ibuki = import ./home/ibuki.nix;
home-manager.extraSpecialArgs = { inherit inputs; username = "ibuki"; };
}
];
};
# ---------- M1 Macs: nix-darwin + home-manager (primary) ----------
# System + user in one rebuild, mirroring the NixOS host. One entry per
# machine, keyed by login username:
# ibuki — personal MacBook
# yoshida — work MacBook
# Apply with: darwin-rebuild switch --flake ~/dotfiles#<username>
darwinConfigurations = {
ibuki = mkDarwin "ibuki";
yoshida = mkDarwin "yoshida";
};
# ---------- M1 Macs: standalone home-manager (no-sudo alternative) ----------
# Same home/darwin.nix as above, for user-only changes without touching
# the system. Apply with: home-manager switch --flake ~/dotfiles#<username>@mac
# allowUnfree is set on the pkgs we pass in (claude-code is unfree); the
# NixOS host and nix-darwin host set the same flag in their system config.
homeConfigurations = {
"ibuki@mac" = mkDarwinHome "ibuki";
"yoshida@mac" = mkDarwinHome "yoshida";
};
# `nix develop` — tooling for tests/check.sh and tests/format.sh.
devShells = forAllSystems (system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
default = pkgs.mkShell {
packages = with pkgs; [
shellcheck
shfmt
nixpkgs-fmt
statix
deadnix
lua
taplo
jq
];
};
});
# `nix fmt` — formats every .nix file in the tree.
formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.nixpkgs-fmt);
};
}