1

Initialize nix-darwin config for darwinix

This commit is contained in:
2026-03-21 12:47:53 +01:00
parent 3573a705af
commit c13dcf6a9f
6 changed files with 351 additions and 3 deletions

View File

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

@ -1,13 +1,14 @@
{ {
inputs, inputs,
pkgs, pkgs,
darwinPkgs,
lib, lib,
... ...
}: { }: {
# Import my own library functions. # Import my own library functions.
# Those are defined as functions returning sets of library functions, # Those are defined as functions returning sets of library functions,
# so those functions have to be called when importing. # so those functions have to be called when importing.
nixos = import ./nixos.nix {inherit inputs pkgs lib;}; nixos = import ./nixos.nix {inherit inputs pkgs darwinPkgs lib;};
modules = import ./modules.nix {inherit inputs pkgs lib;}; modules = import ./modules.nix {inherit inputs pkgs lib;};
networking = import ./networking.nix {inherit inputs pkgs lib;}; networking = import ./networking.nix {inherit inputs pkgs lib;};
rofi = import ./rofi.nix {inherit inputs pkgs lib;}; rofi = import ./rofi.nix {inherit inputs pkgs lib;};

View File

@ -1,6 +1,7 @@
{ {
inputs, inputs,
pkgs, pkgs,
darwinPkgs,
lib, lib,
... ...
}: { }: {
@ -80,6 +81,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 = darwinPkgs;}
# 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 = { mkNixosSystemConfig = {
system, system,
mylib, mylib,

View File

@ -0,0 +1,49 @@
{
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}"
];
};
environment.systemPackages = with pkgs; [
wget
alejandra
];
programs = {
fish.enable = true;
neovim.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; shell = pkgs.fish;
openssh.authorizedKeys.keys = [ openssh.authorizedKeys.keys = [
publicKeys.christoph.ssh publicKeys.${username}.ssh
]; ];
# We do this with HomeManager # We do this with HomeManager