From bdf163a50a8b96d19029552c008831be00933a70 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Wed, 12 Mar 2025 01:51:12 +0000 Subject: [PATCH] consolidate build functions --- flake.nix | 78 +++++++++---------- lib/default.nix | 36 +++++---- .../modules/nmasur/profiles/common.nix | 4 + .../modules/nmasur/profiles/darwin-base.nix | 3 + 4 files changed, 67 insertions(+), 54 deletions(-) diff --git a/flake.nix b/flake.nix index a9157a1..a62c676 100644 --- a/flake.nix +++ b/flake.nix @@ -255,45 +255,45 @@ rec { inherit lib; - # inherit buildDarwin pkgsBySystem; - # - # # Contains my full system builds, including home-manager - # # nixos-rebuild switch --flake .#tempest - # nixosConfigurations = - # (builtins.mapAttrs ( - # name: module: - # buildNixos { - # pkgs = pkgsBySystem.x86_64-linux; - # modules = [ module ]; - # } - # ) x86_64-linux-hosts) - # // (builtins.mapAttrs ( - # name: module: - # buildNixos { - # pkgs = pkgsBySystem.aarch64-linux; - # modules = [ module ]; - # } - # ) aarch64-linux-hosts); - # - # # Contains my full Mac system builds, including home-manager - # # darwin-rebuild switch --flake .#lookingglass - # darwinConfigurations = builtins.mapAttrs ( - # name: module: - # buildDarwin { - # pkgs = pkgsBySystem.aarch64-darwin; - # modules = [ module ]; - # } - # ) aarch64-darwin-hosts; - # - # # For quickly applying home-manager settings with: - # # home-manager switch --flake .#tempest - # homeConfigurations = builtins.mapAttrs ( - # name: module: - # buildHome { - # pkgs = pkgsBySystem.x86_64-linux; - # module = [ module ]; - # } - # ) nixosModules; + + nixosConfigurations = builtins.mapAttrs ( + system: hosts: + builtins.mapAttrs ( + name: module: + lib.buildNixos { + inherit system module; + specialArgs = { inherit (globals) hostnames; }; + } + ) hosts + ) lib.linuxHosts; + + darwinConfigurations = builtins.mapAttrs ( + system: hosts: + builtins.mapAttrs ( + name: module: + lib.buildDarwin { + inherit system module; + } + ) hosts + ) lib.darwinHosts; + + homeModules = builtins.mapAttrs ( + system: hosts: + builtins.mapAttrs ( + name: module: (builtins.head (lib.attrsToList module.home-manager.users)).value + ) hosts + ) lib.hosts; + + homeConfigurations = builtins.mapAttrs ( + system: hosts: + builtins.mapAttrs ( + name: module: + lib.buildHome { + inherit system module; + specialArgs = { inherit (globals) hostnames; }; + } + ) hosts + ) homeModules; # Disk formatting, only used once diskoConfigurations = { diff --git a/lib/default.nix b/lib/default.nix index ae1bcbd..7b11375 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -7,6 +7,7 @@ in lib // rec { + # Returns all files in a directory matching a suffix filesInDirectoryWithSuffix = directory: suffix: lib.pipe (lib.filesystem.listFilesRecursive directory) [ @@ -103,49 +104,54 @@ lib buildHome = { - pkgs, - modules, + system, + module, + specialArgs, }: inputs.home-manager.lib.homeManagerConfiguration { - inherit pkgs; - modules = modules ++ [ + pkgs = pkgsBySystem.${system}; + modules = [ ../platforms/home-manager + module ]; + extraSpecialArgs = { + inherit colorscheme; + } // specialArgs; }; buildNixos = { - pkgs, - modules, + system, + module, specialArgs, }: inputs.nixpkgs.lib.nixosSystem { - inherit pkgs; - modules = modules ++ [ + pkgs = pkgsBySystem.${system}; + modules = [ inputs.home-manager.nixosModules.home-manager inputs.disko.nixosModules.disko inputs.wsl.nixosModules.wsl ../platforms/nixos + module { home-manager.extraSpecialArgs = { - hostnames = globals.hostnames; inherit colorscheme; - }; + } // specialArgs; } ]; specialArgs = { - hostnames = globals.hostnames; - }; + } // specialArgs; }; buildDarwin = - { pkgs, modules }: + { system, module }: inputs.darwin.lib.darwinSystem { - inherit pkgs; - modules = modules ++ [ + pkgs = pkgsBySystem.${system}; + modules = [ inputs.home-manager.darwinModules.home-manager inputs.mac-app-util.darwinModules.default ./platforms/nix-darwin + module ]; }; diff --git a/platforms/home-manager/modules/nmasur/profiles/common.nix b/platforms/home-manager/modules/nmasur/profiles/common.nix index 0bd15f5..a694bdd 100644 --- a/platforms/home-manager/modules/nmasur/profiles/common.nix +++ b/platforms/home-manager/modules/nmasur/profiles/common.nix @@ -13,6 +13,10 @@ in config = lib.mkIf cfg.enable { + home.username = config.nmasur.settings.username; + home.homeDirectory = + if pkgs.stdenv.isDarwin then "/Users/${config.home.username}" else "/home/${config.home.username}"; + home.packages = [ pkgs.dig # DNS lookup pkgs.fd # find diff --git a/platforms/home-manager/modules/nmasur/profiles/darwin-base.nix b/platforms/home-manager/modules/nmasur/profiles/darwin-base.nix index 0a5f884..26b940e 100644 --- a/platforms/home-manager/modules/nmasur/profiles/darwin-base.nix +++ b/platforms/home-manager/modules/nmasur/profiles/darwin-base.nix @@ -14,6 +14,9 @@ in options.nmasur.profiles.darwin-base.enable = lib.mkEnableOption "Base macOS home-manager config"; config = lib.mkIf cfg.enable { + + home.homeDirectory = lib.mkForce "/Users/${config.home.username}"; + # Default shell setting doesn't work home.sessionVariables = { SHELL = "${pkgs.fish}/bin/fish";