diff --git a/flake.nix b/flake.nix index 56e84998..34c4c3a5 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,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. # They are made available to the system and HM configs by inheriting mylib. mylib = import ./lib { @@ -153,6 +172,12 @@ inherit (nixpkgs) lib; }; + darwinMylib = import ./lib { + inherit inputs; + 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 +202,18 @@ # Local shell for NixFlake directory 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. # 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/default.nix b/lib/default.nix index 1fbecca5..16fc1553 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,13 +1,14 @@ { inputs, pkgs, + darwinPkgs, lib, ... }: { # Import my own library functions. # Those are defined as functions returning sets of library functions, # 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;}; networking = import ./networking.nix {inherit inputs pkgs lib;}; rofi = import ./rofi.nix {inherit inputs pkgs lib;}; diff --git a/lib/nixos.nix b/lib/nixos.nix index 4bb8e484..e96c26bb 100644 --- a/lib/nixos.nix +++ b/lib/nixos.nix @@ -1,6 +1,7 @@ { inputs, pkgs, + darwinPkgs, 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 = { system, mylib, diff --git a/system/darwinix/default.nix b/system/darwinix/default.nix new file mode 100644 index 00000000..29769c34 --- /dev/null +++ b/system/darwinix/default.nix @@ -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; +} 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