1

Initialize nix-darwin config for darwinix

This commit is contained in:
2026-03-21 12:47:53 +01:00
parent 3573a705af
commit 0e95468320
5 changed files with 356 additions and 2 deletions

View File

@ -12,8 +12,12 @@
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
hardware.url = "github:nixos/nixos-hardware";
# Darwin
nix-darwin.url = "github:nix-darwin/nix-darwin/master";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
# NOTE: Update this after May and November
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-25.05";
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-25.11";
# Home Manager
home-manager.url = "github:nix-community/home-manager";
@ -91,12 +95,14 @@
outputs = {
self,
nixpkgs,
nix-darwin,
...
} @ inputs: let
# Our configuration is buildable on the following system/platform.
# Configs can support more than a single system simultaneously,
# e.g. NixOS (linux) and MacOS (darwin) or Arm.
system = "x86_64-linux";
darwinSystem = "aarch64-darwin";
# We configure our global packages here.
# Usually, "nixpkgs.legacyPackages.${system}" is used (and more efficient),
@ -139,6 +145,16 @@
];
};
darwinPkgs = import nixpkgs {
system = darwinSystem;
hostPlatform = darwinSystem;
config.allowUnfree = true;
config.allowUnfreePredicate = pkg: true;
overlays = [];
};
# My own library functions are imported here.
# They are made available to the system and HM configs by inheriting mylib.
mylib = import ./lib {
@ -153,6 +169,14 @@
inherit (nixpkgs) lib;
};
darwinMylib = import ./lib {
inherit inputs darwinPkgs;
inherit (nixpkgs) lib;
pkgs = darwinPkgs;
};
# NOTE: Keep public keys here so they're easy to rotate
publicKeys.christoph = {
# /home/christoph/.ssh/id_ed25519.pub
@ -177,6 +201,19 @@
# Local shell for NixFlake directory
devShells.${system}.default = import ./shell.nix {inherit pkgs;};
# Usage: sudo darwin-rebuild switch --flake .#darwinix
darwinConfigurations = {
darwinix = darwinMylib.nixos.mkDarwinConfigWithHomeManagerModule {
inherit publicKeys;
system = darwinSystem;
mylib = darwinMylib;
hostname = "darwinix";
username = "christoph";
extraModules = [];
};
};
# We give each configuration a (host)name to choose a configuration when rebuilding.
# This makes it easy to add different configurations (e.g. for a laptop).
# Usage: sudo nixos-rebuild switch --flake .#nixinator

View File

@ -0,0 +1,185 @@
{
pkgs,
nixosConfig,
config,
lib,
mylib,
username,
inputs,
...
}: {
home = {
inherit username;
homeDirectory = "/Users/${config.home.username}";
enableNixpkgsReleaseCheck = true;
packages = with pkgs; [
(ripgrep.override {withPCRE2 = true;})
gdu
duf
sd
cachix
];
stateVersion = "25.11";
};
programs = {
home-manager.enable = true;
# TODO: Module
fastfetch = {
enable = true;
settings = {
logo = {
padding = {
top = 4;
left = 1;
right = 2;
};
};
display = {
separator = "";
key.width = 17;
};
# Box Drawing: ╭ ─ ╮ ╰ ╯ │
modules = [
# Title
{
type = "title";
format = "{#1} {#}{user-name-colored}";
}
# System Information
{
type = "custom";
format = "{#1} {#}System Information";
}
{
type = "os";
key = "{#separator} {#keys}󰍹 OS";
}
{
type = "kernel";
key = "{#separator} {#keys}󰒋 Kernel";
}
{
type = "bootmgr";
key = "{#separator} {#keys}󰒋 BootMGR";
}
{
type = "uptime";
key = "{#separator} {#keys}󰅐 Uptime";
}
{
type = "packages";
key = "{#separator} {#keys}󰏖 Packages";
# format = "{all}";
}
{
type = "custom";
format = "{#1}";
}
# Desktop Environment
{
type = "custom";
format = "{#1} {#}Desktop Environment";
}
{
type = "de";
key = "{#separator} {#keys}󰧨 DE";
}
{
type = "wm";
key = "{#separator} {#keys}󱂬 WM";
}
{
type = "wmtheme";
key = "{#separator} {#keys}󰉼 Theme";
}
{
type = "display";
key = "{#separator} {#keys}󰹑 Resolution";
}
{
type = "shell";
key = "{#separator} {#keys}󰞷 Shell";
}
{
type = "terminalfont";
key = "{#separator} {#keys}󰛖 Font";
}
{
type = "icons";
key = "{#separator} {#keys} Icons";
}
{
type = "cursor";
key = "{#separator} {#keys}󰆽 Cursor";
}
{
type = "custom";
format = "{#1}";
}
# Hardware Information
{
type = "custom";
format = "{#1} {#}Hardware Information";
}
{
type = "board";
key = "{#separator} {#keys} Board";
}
{
type = "cpu";
key = "{#separator} {#keys}󰻠 CPU";
}
{
type = "gpu";
key = "{#separator} {#keys}󰢮 GPU";
}
{
type = "memory";
key = "{#separator} {#keys}󰍛 Memory";
}
# {
# type = "disk";
# key = "{#separator}│ {#keys}󰋊 Disk (/)";
# folders = "/";
# }
# {
# type = "disk";
# key = "{#separator}│ {#keys}󰋊 Disk (~/Games)";
# folders = "/home/christoph/Games";
# }
{
type = "btrfs";
key = "{#separator} {#keys}󰋊 BTRFS";
}
{
type = "custom";
format = "{#1}";
}
# Colors Footer
{
type = "colors";
key = "{#separator} {#1}";
keyWidth = 6;
symbol = "circle";
}
];
};
};
};
services = {
};
}

View File

@ -80,6 +80,81 @@
];
};
mkDarwinConfigWithHomeManagerModule = {
system,
mylib,
hostname,
username,
publicKeys,
extraModules ? [],
}:
inputs.nix-darwin.lib.darwinSystem {
inherit system;
# Values in "specialArgs" are propagated to all system modules.
specialArgs = {
inherit inputs system hostname mylib username publicKeys;
};
modules = builtins.concatLists [
[
# Replace the default "pkgs" with my configured version
# to allow installation of unfree software and my own overlays.
{nixpkgs.pkgs = pkgs;}
# Import the toplevel system configuration module.
# ../system # TODO:
../system/cachix.nix
# Host specific configuration
../system/${hostname}
# Import all of my custom system modules
# ../system/systemmodules # TODO:
]
extraModules
# HM is installed as a system module when using mkNixosConfigWithHomeManagerModule.
[
inputs.home-manager.darwinModules.home-manager
{
home-manager = {
# Values in "extraSpecialArgs" are propagated to all HM modules.
extraSpecialArgs = {
inherit inputs system hostname mylib username publicKeys;
};
# Use the "pkgs" from the system configuration.
# This disables "nixpkgs.*" options in HM modules.
useGlobalPkgs = true;
# Packages in "users.${username}.packages" will be installed
# to /etc/profiles instead of ~/.nix-profile.
useUserPackages = true;
users.${username}.imports = [
# Import the user-specific HM toplevel module.
# It will be merged with the main config (like all different modules).
# Settings regarding a specific host (e.g. desktop or laptop)
# should only be made in the host-specific config.
# ../home/${username} # TODO:
# Host specific configuration
../home/${username}/${hostname}
];
sharedModules = [
# Import all of my custom HM modules.
# Putting them into sharedModules enables correct nixd completions.
# ../home/homemodules # TODO:
];
};
}
]
];
};
mkNixosSystemConfig = {
system,
mylib,

View File

@ -0,0 +1,57 @@
{
self,
lib,
mylib,
pkgs,
username,
config,
inputs,
publicKeys,
...
}: {
nix = {
package = pkgs.nixVersions.stable;
extraOptions = ''
experimental-features = nix-command flakes pipe-operators
'';
settings.trusted-users = ["root" "${username}"];
gc.automatic = false;
gc.options = "--delete-older-than 5d";
settings.auto-optimise-store = true;
optimise.automatic = true;
registry = lib.mapAttrs' (n: v: lib.nameValuePair n {flake = v;}) inputs;
nixPath = [
"nixpkgs=${inputs.nixpkgs.outPath}"
"home-manager=${inputs.home-manager.outPath}"
];
};
users.users.${username} = {
isHidden = false;
openssh.authorizedKeys.keys = [
publicKeys.${username}.ssh
];
};
environment.systemPackages = with pkgs; [
alejandra
neovim
wget
];
programs = {
fish.enable = true;
};
# Set Git commit hash for darwin-version.
system.configurationRevision = self.rev or self.dirtyRev or null;
# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 6;
}

View File

@ -276,7 +276,7 @@ with mylib.networking; {
shell = pkgs.fish;
openssh.authorizedKeys.keys = [
publicKeys.christoph.ssh
publicKeys.${username}.ssh
];
# We do this with HomeManager