Files
MacNix-config/flake.nix
2026-09-15 20:46:52 +02:00

229 lines
5.5 KiB
Nix

{
description = "Starter configuration for macOS with nix-darwin";
inputs = {
nixpkgsAarch64 = {
url = "github:nixos/nixpkgs/nixpkgs-unstable";
};
nixpkgsX86 = {
url = "github:nixos/nixpkgs//nixpkgs-26.05-darwin";
};
homeManagerAarch64 = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgsAarch64";
};
homeManagerX86 = {
url = "github:nix-community/home-manager/release-26.05";
inputs.nixpkgs.follows = "nixpkgsX86";
};
nixd = {
url = "github:nix-community/nixd";
};
darwinAarch64 = {
url = "github:nix-darwin/nix-darwin";
inputs.nixpkgs.follows = "nixpkgsAarch64";
};
darwinX86 = {
url = "github:nix-darwin/nix-darwin/nix-darwin-26.05";
inputs.nixpkgs.follows = "nixpkgsX86";
};
brew-src = {
url = "github:Homebrew/brew/main";
flake = false;
};
nix-homebrew = {
url = "github:zhaofengli-wip/nix-homebrew";
inputs.brew-src.follows = "brew-src";
};
homebrew-core = {
url = "github:homebrew/homebrew-core";
flake = false;
};
homebrew-cask = {
url = "github:homebrew/homebrew-cask";
flake = false;
};
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgsAarch64";
};
nix-vscode-extensions = {
url = "github:nix-community/nix-vscode-extensions";
};
catppuccin = {
url = "github:catppuccin/nix";
};
llm-agents = {
url = "github:numtide/llm-agents.nix";
};
# mac-app-util doesn't work with OCLP installed on X86
# mac-app-util = {
# url = "github:hraban/mac-app-util";
# };
};
outputs =
{
self,
darwinAarch64,
darwinX86,
nix-homebrew,
homebrew-core,
homebrew-cask,
homeManagerAarch64,
homeManagerX86,
nixpkgsAarch64,
nixpkgsX86,
nixd,
sops-nix,
nix-vscode-extensions,
catppuccin,
llm-agents,
...
}@inputs:
let
user = "olaf";
lib = nixpkgsAarch64.lib;
darwinSystems = [
"aarch64-darwin"
"x86_64-darwin"
];
perSystem = {
aarch64-darwin = {
nixpkgs = nixpkgsAarch64;
darwin = darwinAarch64;
home-manager = homeManagerAarch64;
pkgs = nixpkgsAarch64.legacyPackages.aarch64-darwin;
};
x86_64-darwin = {
nixpkgs = nixpkgsX86;
darwin = darwinX86;
home-manager = homeManagerX86;
pkgs = nixpkgsX86.legacyPackages.x86_64-darwin;
};
};
forAllSystems = f: lib.genAttrs darwinSystems f;
devShell =
system:
let
pkgs = perSystem.${system}.pkgs;
in
{
default =
with pkgs;
mkShell {
nativeBuildInputs = with pkgs; [
bashInteractive
git
pkgs.nixd
];
packages = with pkgs; [
platformio-core
(writeShellScriptBin "python" ''
if [ "$1" = "-m" ] && [ "$2" = "platformio" ]; then
shift 2
exec ${platformio-core}/bin/platformio "$@"
fi
exec ${python3}/bin/python3 "$@"
'')
openocd
avrdude
];
shellHook = ''
export EDITOR=vim
export PLATFORMIO_CORE_DIR="$PWD/.platformio"
'';
};
};
mkApp =
scriptName: system:
let
pkgs = perSystem.${system}.pkgs;
in
{
type = "app";
program = "${
(pkgs.writeScriptBin scriptName ''
#!/usr/bin/env bash
PATH=${pkgs.git}/bin:$PATH
echo "Running ${scriptName} for ${system}"
sudo chmod +x ${self}/apps/${system}/${scriptName}
exec ${self}/apps/${system}/${scriptName}
'')
}/bin/${scriptName}";
};
mkDarwinApps = system: {
"apply" = mkApp "apply" system;
"build" = mkApp "build" system;
"build-switch" = mkApp "build-switch" system;
"rollback" = mkApp "rollback" system;
};
in
{
devShells = forAllSystems devShell;
apps = lib.genAttrs darwinSystems mkDarwinApps;
darwinConfigurations = lib.genAttrs darwinSystems (
system:
let
systemConfig = perSystem.${system};
in
systemConfig.darwin.lib.darwinSystem {
inherit system;
specialArgs = inputs // {
inherit system;
nixpkgs = systemConfig.nixpkgs;
darwin = systemConfig.darwin;
home-manager = systemConfig.home-manager;
};
modules = [
systemConfig.home-manager.darwinModules.home-manager
nix-homebrew.darwinModules.nix-homebrew
{
nix-homebrew = {
inherit user;
enable = true;
taps = {
"homebrew/homebrew-core" = homebrew-core;
"homebrew/homebrew-cask" = homebrew-cask;
};
mutableTaps = false;
autoMigrate = true;
};
home-manager.sharedModules =
lib.optionals (system != "x86_64-darwin") [
catppuccin.homeModules.catppuccin
];
}
./hosts/darwin
];
}
);
};
}