From 1c426b19e3e8f46acdcc975dd501297ff71e3538 Mon Sep 17 00:00:00 2001 From: Christoph Urlacher Date: Sat, 21 Mar 2026 12:47:53 +0100 Subject: [PATCH] Initialize nix-darwin config for darwinix --- flake.nix | 39 +++++- home/christoph/darwinix/default.nix | 185 ++++++++++++++++++++++++++++ lib/nixos.nix | 75 +++++++++++ system/darwinix/default.nix | 65 ++++++++++ system/default.nix | 2 +- 5 files changed, 364 insertions(+), 2 deletions(-) create mode 100644 home/christoph/darwinix/default.nix create mode 100644 system/darwinix/default.nix diff --git a/flake.nix b/flake.nix index 56e84998..24cb83b3 100644 --- a/flake.nix +++ b/flake.nix @@ -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 diff --git a/home/christoph/darwinix/default.nix b/home/christoph/darwinix/default.nix new file mode 100644 index 00000000..fa0344f7 --- /dev/null +++ b/home/christoph/darwinix/default.nix @@ -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 = { + }; +} diff --git a/lib/nixos.nix b/lib/nixos.nix index 4bb8e484..c51bb206 100644 --- a/lib/nixos.nix +++ b/lib/nixos.nix @@ -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, diff --git a/system/darwinix/default.nix b/system/darwinix/default.nix new file mode 100644 index 00000000..58ba0991 --- /dev/null +++ b/system/darwinix/default.nix @@ -0,0 +1,65 @@ +{ + 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; + description = "Christoph"; + home = "/Users/${username}"; + createHome = false; + + # NOTE: Not set if the user already exists on darwin, so use chsh for the root user + shell = pkgs.fish; + + openssh.authorizedKeys.keys = [ + publicKeys.${username}.ssh + ]; + + # packages = with pkgs; []; + }; + + 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; +} diff --git a/system/default.nix b/system/default.nix index c2c9f5fc..e74a129f 100644 --- a/system/default.nix +++ b/system/default.nix @@ -276,7 +276,7 @@ with mylib.networking; { shell = pkgs.fish; openssh.authorizedKeys.keys = [ - publicKeys.christoph.ssh + publicKeys.${username}.ssh ]; # We do this with HomeManager