save progress

This commit is contained in:
2025-01-07 19:17:44 -05:00
parent 20a02e8cab
commit 5badd8e774
6 changed files with 142 additions and 93 deletions

221
flake.nix
View File

@@ -1,11 +1,17 @@
{ {
description = "Example Darwin system flake"; description = "Example multi-host, multi-user Darwin system flake with hostVars/userVars, using let-bindings and strict commas";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nix-darwin.url = "github:LnL7/nix-darwin"; nix-darwin.url = "github:LnL7/nix-darwin";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew"; nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew";
homebrew-core = { homebrew-core = {
url = "github:homebrew/homebrew-core"; url = "github:homebrew/homebrew-core";
@@ -19,111 +25,140 @@
url = "github:homebrew/homebrew-bundle"; url = "github:homebrew/homebrew-bundle";
flake = false; flake = false;
}; };
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
}; };
outputs = inputs@{ self, nix-darwin, nix-homebrew, home-manager, ... }: outputs = inputs@{ self, nix-darwin, home-manager, ... }:
let let
username = "stephen"; ###################################
hostname = "swaphb-mba"; # 1. Host variables
###################################
# Minimal Darwin system config (minus environment.systemPackages/services) hostVars = {
configuration = { pkgs, lib, inputs, ... }: { host1 = {
# Some general Darwin/Nix configuration hostname = "swaphb-mba";
nix.extraOptions = '' arch = "aarch64-darwin";
experimental-features = nix-command flakes
'';
# This can stay here or move to modules/darwin/services.nix
# services.nix-daemon.enable = true;
# Enable the nix-darwin module system.
nix.package = pkgs.nix;
# Necessary for using flakes on this system.
nix.settings.experimental-features = "nix-command flakes";
# zsh, fish, etc.
programs.zsh.enable = true;
programs.bash.interactiveShellInit = ''
source /home/${username}/.config/op/plugins.sh
'';
system.configurationRevision = self.rev or self.dirtyRev or null;
system.defaults = {
# ...
}; };
host2 = {
system.stateVersion = 4; hostname = "example";
nixpkgs.hostPlatform = "aarch64-darwin"; arch = "aarch64-darwin";
nixpkgs.config = {
allowUnfree = true;
allowBroken = true;
}; };
}; };
# Minimal home-manager config (minus dotfiles) ###################################
homeconfig = { pkgs, lib, ... }: { # 2. User variables
home.stateVersion = "24.05"; ###################################
programs.home-manager.enable = true; userVars = {
userA = {
home.packages = with pkgs; [ ]; username = "stephen";
home.sessionVariables = { homeDirectory = "/Users/stephen";
EDITOR = "nano"; shell = "zsh";
};
userB = {
username = "example";
homeDirectory = "/Users/example";
shell = "fish";
}; };
home.homeDirectory = lib.mkForce "/Users/${username}";
}; };
###################################
# 3. Base Darwin config function
###################################
baseDarwinConfig = hostKey:
{ config, pkgs, ... }:
{
nixpkgs.hostPlatform = hostVars.${hostKey}.arch;
nix.extraOptions = ''
experimental-features = nix-command flakes
'';
nix.package = pkgs.nix;
nix.settings.experimental-features = "nix-command flakes";
system.configurationRevision = self.rev or self.dirtyRev or null;
nixpkgs.config.allowUnfree = true;
nixpkgs.config.allowBroken = true;
};
in in
{ {
darwinConfigurations."${hostname}" = nix-darwin.lib.darwinSystem { ###################################
modules = # 4. Host 1: swaphb-mba
[ ###################################
# Main Darwin config darwinConfigurations."${hostVars.host1.hostname}" = let
configuration host1Base = baseDarwinConfig "host1";
in
# The official nix-homebrew module from your flake inputs nix-darwin.lib.darwinSystem {
nix-homebrew.darwinModules.nix-homebrew modules = [
{ host1Base,
nix-homebrew = { ./modules/darwin/homebrew.nix,
enable = true; ./modules/darwin/services.nix,
enableRosetta = true; ./modules/darwin/nixpackages.nix,
user = "${username}"; inputs.nix-homebrew.darwinModules.nix-homebrew,
taps = { {
"homebrew/homebrew-core" = inputs.homebrew-core; nix-homebrew = {
"homebrew/homebrew-cask" = inputs.homebrew-cask; enable = true;
"homebrew/homebrew-bundle" = inputs.homebrew-bundle; enableRosetta = true;
}; user = userVars.userA.username;
autoMigrate = true; taps = {
mutableTaps = false; "homebrew/homebrew-core" = inputs.homebrew-core;
"homebrew/homebrew-cask" = inputs.homebrew-cask;
"homebrew/homebrew-bundle" = inputs.homebrew-bundle;
}; };
} autoMigrate = true;
mutableTaps = false;
};
},
home-manager.darwinModules.home-manager {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.verbose = true;
# Our own modules for Darwin-level configs home-manager.users.${userVars.userA.username} = {
./modules/darwin/homebrew.nix home.homeDirectory = userVars.userA.homeDirectory;
./modules/darwin/nixpackages.nix programs.zsh.enable = (userVars.userA.shell == "zsh");
./modules/darwin/services.nix programs.fish.enable = (userVars.userA.shell == "fish");
imports = [
# Home Manager ./modules/home/${userVars.userA.username}/dotfiles.nix
home-manager.darwinModules.home-manager ];
{ };
home-manager.useGlobalPkgs = true; }
home-manager.useUserPackages = true; ];
home-manager.verbose = true;
home-manager.users.${username} = {
imports = [
homeconfig
./modules/home/dotfiles.nix
];
};
}
];
}; };
darwinPackages = self.darwinConfigurations."${hostname}".pkgs; ###################################
}; # 5. Host 2: example
###################################
darwinConfigurations."${hostVars.host2.hostname}" = let
host2Base = baseDarwinConfig "host2";
in
nix-darwin.lib.darwinSystem {
modules = [
host2Base,
./modules/darwin/homebrew.nix,
./modules/darwin/services.nix,
./modules/darwin/nixpackages.nix,
home-manager.darwinModules.home-manager {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.verbose = true;
home-manager.users.${userVars.userB.username} = {
home.homeDirectory = userVars.userB.homeDirectory;
programs.zsh.enable = (userVars.userB.shell == "zsh");
programs.fish.enable = (userVars.userB.shell == "fish");
imports = [
./modules/home/${userVars.userB.username}/dotfiles.nix
];
};
}
];
};
###################################
# 6. (Optional) Expose packages
###################################
darwinPackages = {
"${hostVars.host1.hostname}" = self.darwinConfigurations."${hostVars.host1.hostname}".pkgs;
"${hostVars.host2.hostname}" = self.darwinConfigurations."${hostVars.host2.hostname}".pkgs;
};
}
} }

View File

@@ -21,6 +21,7 @@
"teleport-connect" "teleport-connect"
"utm" "utm"
"localsend" "localsend"
"joplin"
]; ];
masApps = { masApps = {
"1Password for Safari" = 1569813296; "1Password for Safari" = 1569813296;

View File

View File

@@ -0,0 +1,13 @@
{ config, pkgs, lib, ... }:
{
home.file.".gitconfig".text = ''
[user]
name = "User B"
email = "userA@example.com"
'';
home.file.".zshrc".text = ''
# userA's custom zsh config
'';
}

View File