From bf273925ad121ad0711c80afd1dd7a27a64b6f34 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Tue, 11 Mar 2025 02:31:22 +0000 Subject: [PATCH] still working on consolidating --- colorscheme/default.nix | 20 ---- flake.nix | 187 ++++++++++---------------------- hosts/aarch64-linux/default.nix | 22 ---- lib/default.nix | 88 +++++++++++++++ overlays/default.nix | 16 --- 5 files changed, 144 insertions(+), 189 deletions(-) delete mode 100644 colorscheme/default.nix delete mode 100644 hosts/aarch64-linux/default.nix delete mode 100644 overlays/default.nix diff --git a/colorscheme/default.nix b/colorscheme/default.nix deleted file mode 100644 index 8adb6f8..0000000 --- a/colorscheme/default.nix +++ /dev/null @@ -1,20 +0,0 @@ -# Return an atrset of all colorschemes - -nixpkgs: - -let - inherit (nixpkgs) lib; -in - -lib.pipe (lib.filesystem.listFilesRecursive ./.) [ - # Get only files ending in default.nix - (builtins.filter (name: lib.hasSuffix "default.nix" name)) - # Import each colorscheme function - (map (file: { - name = builtins.baseNameOf (builtins.dirOf file); - value = import file; - })) - # Convert to an attrset of colorscheme -> colors - (builtins.listToAttrs) - -] diff --git a/flake.nix b/flake.nix index 28f9d80..a9157a1 100644 --- a/flake.nix +++ b/flake.nix @@ -211,6 +211,7 @@ { nixpkgs, ... }@inputs: let + lib = import ./lib inputs; # Global configuration for my systems globals = @@ -250,136 +251,53 @@ }; }; - colorscheme = import ./colorscheme; - - # Common overlays to always use - overlays = [ - inputs.nur.overlays.default - inputs.nix2vim.overlay - ] ++ (import ./overlays inputs); - - # System types to support. - supportedSystems = [ - "x86_64-linux" - "x86_64-darwin" - "aarch64-linux" - "aarch64-darwin" - ]; - - # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. - forAllSystems = nixpkgs.lib.genAttrs supportedSystems; - - # { system -> pkgs } - pkgsBySystem = forAllSystems ( - system: - import nixpkgs { - inherit system overlays; - config.permittedInsecurePackages = [ "litestream-0.3.13" ]; - config.allowUnfree = true; - } - ); - # stablePkgsBySystem = forAllSystems (system: import nixpkgs { inherit system overlays; }); - - buildHome = - { pkgs, modules }: - inputs.home-manager.lib.homeManagerConfiguration { - inherit pkgs; - modules = modules ++ [ - ./platforms/home-manager - ]; - }; - - buildNixos = - { pkgs, modules }: - nixpkgs.lib.nixosSystem { - inherit pkgs; - modules = modules ++ [ - inputs.home-manager.nixosModules.home-manager - inputs.disko.nixosModules.disko - inputs.wsl.nixosModules.wsl - ./platforms/nixos - { - home-manager.extraSpecialArgs = { - hostnames = globals.hostnames; - inherit colorscheme; - }; - } - ]; - specialArgs = { - hostnames = globals.hostnames; - }; - }; - - buildDarwin = - { pkgs, modules }: - inputs.darwin.lib.darwinSystem { - inherit pkgs; - modules = modules ++ [ - inputs.home-manager.darwinModules.home-manager - inputs.mac-app-util.darwinModules.default - ./platforms/nix-darwin - ]; - }; - - x86_64-linux-hosts = (import ./hosts nixpkgs).x86_64-linux-hosts; - aarch64-linux-hosts = (import ./hosts nixpkgs).aarch64-linux-hosts; - aarch64-darwin-hosts = (import ./hosts nixpkgs).aarch64-darwin-hosts; - in rec { - # The plan - # Import all the host configurations as modules - # Setup the modules as nixosModules, homeModules, darwinModules - # Create nixosConfigurations using the different pkgs for each system - # What to do with home config? - - nixosModules = x86_64-linux-hosts // aarch64-linux-hosts; - darwinModules = aarch64-darwin-hosts; - - 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; + 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; # Disk formatting, only used once diskoConfigurations = { - root = import ./disks/root.nix; + root = import ./hosts/x86_64-linux/swan/root.nix; }; # packages = @@ -437,17 +355,21 @@ # aarch64-darwin.neovim = neovim "aarch64-darwin"; # }; - packages = forAllSystems (system: pkgsBySystem.${system}.nmasur); + # Get the custom packages that I have placed under the nmasur namespace + packages = lib.forAllSystems (system: lib.pkgsBySystem.${system}.nmasur); # Development environments - devShells = forAllSystems (system: { - default = pkgsBySystem.${system}.nmasur.dotfiles-devshell; + devShells = lib.forAllSystems (system: { + default = lib.pkgsBySystem.${system}.nmasur.dotfiles-devshell; }); - checks = forAllSystems ( + checks = lib.forAllSystems ( system: let - pkgs = import nixpkgs { inherit system overlays; }; + pkgs = import nixpkgs { + inherit system; + overlays = lib.overlays; + }; in { neovim = @@ -466,10 +388,13 @@ } ); - formatter = forAllSystems ( + formatter = lib.forAllSystems ( system: let - pkgs = import nixpkgs { inherit system overlays; }; + pkgs = import nixpkgs { + inherit system; + inherit (lib) overlays; + }; in pkgs.nixfmt-rfc-style ); diff --git a/hosts/aarch64-linux/default.nix b/hosts/aarch64-linux/default.nix deleted file mode 100644 index 0d927f6..0000000 --- a/hosts/aarch64-linux/default.nix +++ /dev/null @@ -1,22 +0,0 @@ -# Return a list of all NixOS hosts - -{ nixpkgs, ... }: - -let - inherit (nixpkgs) lib; -in - -lib.pipe (lib.filesystem.listFilesRecursive ./.) [ - # Get only files ending in default.nix - (builtins.filter (name: lib.hasSuffix "default.nix" name)) - # Remove this file - (builtins.filter (name: name != ./default.nix)) - # Import each host function - map - (file: { - name = builtins.baseNameOf (builtins.dirOf file); - value = import file; - }) - # Convert to an attrset of hostname -> host function - (builtins.listToAttrs) -] diff --git a/lib/default.nix b/lib/default.nix index ad1f064..ae1bcbd 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -61,4 +61,92 @@ lib )) ]; + # Common overlays to always use + overlays = [ + inputs.nur.overlays.default + inputs.nix2vim.overlay + ] ++ (importOverlays ../overlays); + + # System types to support. + supportedSystems = [ + "x86_64-linux" + "x86_64-darwin" + "aarch64-linux" + "aarch64-darwin" + ]; + + # Split system types by operating system + linuxSystems = builtins.filter (lib.hasSuffix "linux") supportedSystems; + darwinSystems = builtins.filter (lib.hasSuffix "darwin") supportedSystems; + + # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. + forSystems = systems: lib.genAttrs systems; + forAllSystems = lib.genAttrs supportedSystems; + + # { x86_64-linux = { tempest = { settings = ...; }; }; }; + hosts = forAllSystems (system: defaultFilesToAttrset ../hosts/${system}); + + linuxHosts = lib.filterAttrs (name: value: builtins.elem name linuxSystems) hosts; + darwinHosts = lib.filterAttrs (name: value: builtins.elem name darwinSystems) hosts; + + # { system -> pkgs } + pkgsBySystem = forAllSystems ( + system: + import inputs.nixpkgs { + inherit system overlays; + config.permittedInsecurePackages = [ "litestream-0.3.13" ]; + config.allowUnfree = true; + } + ); + + colorscheme = defaultFilesToAttrset ../colorscheme; + + buildHome = + { + pkgs, + modules, + }: + inputs.home-manager.lib.homeManagerConfiguration { + inherit pkgs; + modules = modules ++ [ + ../platforms/home-manager + ]; + }; + + buildNixos = + { + pkgs, + modules, + specialArgs, + }: + inputs.nixpkgs.lib.nixosSystem { + inherit pkgs; + modules = modules ++ [ + inputs.home-manager.nixosModules.home-manager + inputs.disko.nixosModules.disko + inputs.wsl.nixosModules.wsl + ../platforms/nixos + { + home-manager.extraSpecialArgs = { + hostnames = globals.hostnames; + inherit colorscheme; + }; + } + ]; + specialArgs = { + hostnames = globals.hostnames; + }; + }; + + buildDarwin = + { pkgs, modules }: + inputs.darwin.lib.darwinSystem { + inherit pkgs; + modules = modules ++ [ + inputs.home-manager.darwinModules.home-manager + inputs.mac-app-util.darwinModules.default + ./platforms/nix-darwin + ]; + }; + } diff --git a/overlays/default.nix b/overlays/default.nix deleted file mode 100644 index 096fbdd..0000000 --- a/overlays/default.nix +++ /dev/null @@ -1,16 +0,0 @@ -# Return a list of all overlays - -inputs: - -let - lib = inputs.nixpkgs.lib; -in - -lib.pipe (lib.filesystem.listFilesRecursive ./.) [ - # Get only files ending in .nix - (builtins.filter (name: lib.hasSuffix ".nix" name)) - # Remove this file - (builtins.filter (name: name != ./default.nix)) - # Import each overlay file - (map (file: (import file) inputs)) -]