From a3ad019f4b8f97edd7ff895c6f85d8baf1c9ad60 Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Fri, 14 Mar 2025 00:13:56 +0000 Subject: [PATCH] add generators and clean up directories --- flake.nix | 95 ++++++++----------- lib/default.nix | 55 ++++++++++- .../neovim/nmasur/neovim/config/colors.nix | 19 ++++ .../editors/neovim/nmasur/neovim/package.nix | 2 +- platforms/generators/aws/default.nix | 13 ++- platforms/generators/default.nix | 9 -- platforms/home-manager/default.nix | 9 -- platforms/nix-darwin/default.nix | 9 -- platforms/nixos/default.nix | 9 -- .../nmasur/presets/services/openssh-aws.nix | 27 ++++++ .../nixos/modules/nmasur/profiles/base.nix | 13 --- 11 files changed, 145 insertions(+), 115 deletions(-) delete mode 100644 platforms/generators/default.nix delete mode 100644 platforms/home-manager/default.nix delete mode 100644 platforms/nix-darwin/default.nix delete mode 100644 platforms/nixos/default.nix create mode 100644 platforms/nixos/modules/nmasur/presets/services/openssh-aws.nix diff --git a/flake.nix b/flake.nix index a62c676..62e70d1 100644 --- a/flake.nix +++ b/flake.nix @@ -300,63 +300,48 @@ root = import ./hosts/x86_64-linux/swan/root.nix; }; - # packages = - # let - # staff = - # system: - # import ./hosts/staff { - # inherit - # inputs - # globals - # overlays - # system - # ; - # }; - # neovim = - # system: - # let - # pkgs = import nixpkgs { inherit system overlays; }; - # in - # import ./modules/common/neovim/package { - # inherit pkgs; - # colors = (import ./colorscheme/gruvbox-dark).dark; - # }; - # in - # { - # x86_64-linux.staff = staff "x86_64-linux"; - # x86_64-linux.arrow = inputs.nixos-generators.nixosGenerate rec { - # system = "x86_64-linux"; - # format = "iso"; - # modules = import ./hosts/arrow/modules.nix { inherit inputs globals overlays; }; - # }; - # x86_64-linux.arrow-aws = inputs.nixos-generators.nixosGenerate rec { - # system = "x86_64-linux"; - # format = "amazon"; - # modules = import ./hosts/arrow/modules.nix { inherit inputs globals overlays; } ++ [ - # ( - # { ... }: - # { - # boot.kernelPackages = inputs.nixpkgs.legacyPackages.x86_64-linux.linuxKernel.packages.linux_6_6; - # amazonImage.sizeMB = 16 * 1024; - # permitRootLogin = "prohibit-password"; - # boot.loader.systemd-boot.enable = inputs.nixpkgs.lib.mkForce false; - # boot.loader.efi.canTouchEfiVariables = inputs.nixpkgs.lib.mkForce false; - # services.amazon-ssm-agent.enable = true; - # users.users.ssm-user.extraGroups = [ "wheel" ]; - # } - # ) - # ]; - # }; - - # # Package Neovim config into standalone package - # x86_64-linux.neovim = neovim "x86_64-linux"; - # x86_64-darwin.neovim = neovim "x86_64-darwin"; - # aarch64-linux.neovim = neovim "aarch64-linux"; - # aarch64-darwin.neovim = neovim "aarch64-darwin"; + # generators = { + # arrow.aws.x86_64-linux = lib.generateImage { + # system = "x86_64-linux"; + # format = "amazon"; + # specialArgs = { inherit (globals) hostnames; }; + # }; + # arrow.iso.x86_64-linux = lib.generateImage { + # system = "x86_64-linux"; + # format = "iso"; + # specialArgs = { inherit (globals) hostnames; }; + # }; # }; - # Get the custom packages that I have placed under the nmasur namespace - packages = lib.forAllSystems (system: lib.pkgsBySystem.${system}.nmasur); + generators = builtins.mapAttrs ( + system: hosts: + builtins.mapAttrs (name: module: { + aws = lib.generateImage { + inherit system module; + format = "amazon"; + specialArgs = { inherit (globals) hostnames; }; + }; + iso = lib.generateImage { + inherit system module; + format = "iso"; + specialArgs = { inherit (globals) hostnames; }; + }; + }) hosts + ) lib.linuxHosts; + + packages = lib.forAllSystems ( + system: + # Get the configurations that we normally use + { + nixosConfigurations = nixosConfigurations.${system}; + darwinConfigurations = darwinConfigurations.${system}; + homeConfigurations = homeConfigurations.${system}; + generators = generators.${system}; + } + // + # Get the custom packages that I have placed under the nmasur namespace + lib.pkgsBySystem.${system}.nmasur + ); # Development environments devShells = lib.forAllSystems (system: { diff --git a/lib/default.nix b/lib/default.nix index 7b11375..c6a144a 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -102,6 +102,18 @@ lib colorscheme = defaultFilesToAttrset ../colorscheme; + homeModule = { + home-manager = { + # Include home-manager config in NixOS + sharedModules = nixFiles ../platforms/home-manager; + # Use the system-level nixpkgs instead of Home Manager's + useGlobalPkgs = lib.mkDefault true; + # Install packages to /etc/profiles instead of ~/.nix-profile, useful when + # using multiple profiles for one user + useUserPackages = lib.mkDefault true; + }; + }; + buildHome = { system, @@ -111,7 +123,7 @@ lib inputs.home-manager.lib.homeManagerConfiguration { pkgs = pkgsBySystem.${system}; modules = [ - ../platforms/home-manager + { imports = (nixFiles ../platforms/home-manager); } module ]; extraSpecialArgs = { @@ -131,7 +143,7 @@ lib inputs.home-manager.nixosModules.home-manager inputs.disko.nixosModules.disko inputs.wsl.nixosModules.wsl - ../platforms/nixos + { imports = (nixFiles ../platforms/nixos); } module { home-manager.extraSpecialArgs = { @@ -150,9 +162,46 @@ lib modules = [ inputs.home-manager.darwinModules.home-manager inputs.mac-app-util.darwinModules.default - ./platforms/nix-darwin + { imports = (nixFiles ../platforms/nix-darwin); } module ]; }; + generatorOptions = { + amazon = { + aws.enable = true; + }; + iso = { }; + }; + + generateImage = + { + system, + module, + format, + specialArgs, + }: + inputs.nixos-generators.nixosGenerate { + inherit system format; + modules = [ + inputs.home-manager.nixosModules.home-manager + inputs.disko.nixosModules.disko + inputs.wsl.nixosModules.wsl + { + imports = (nixFiles ../platforms/nixos) ++ (nixFiles ../platforms/generators); + } + generatorOptions.${format} + module + { + home-manager = { + extraSpecialArgs = { + inherit colorscheme; + } // specialArgs; + } // homeModule.home-manager; + } + ]; + specialArgs = { + } // specialArgs; + }; + } diff --git a/pkgs/applications/editors/neovim/nmasur/neovim/config/colors.nix b/pkgs/applications/editors/neovim/nmasur/neovim/config/colors.nix index 7aa048c..8377d66 100644 --- a/pkgs/applications/editors/neovim/nmasur/neovim/config/colors.nix +++ b/pkgs/applications/editors/neovim/nmasur/neovim/config/colors.nix @@ -11,6 +11,25 @@ options.colors = lib.mkOption { type = lib.types.attrsOf lib.types.str; description = "Attrset of base16 colorscheme key value pairs."; + default = { + # Nord + base00 = "#2E3440"; + base01 = "#3B4252"; + base02 = "#434C5E"; + base03 = "#4C566A"; + base04 = "#D8DEE9"; + base05 = "#E5E9F0"; + base06 = "#ECEFF4"; + base07 = "#8FBCBB"; + base08 = "#88C0D0"; + base09 = "#81A1C1"; + base0A = "#5E81AC"; + base0B = "#BF616A"; + base0C = "#D08770"; + base0D = "#EBCB8B"; + base0E = "#A3BE8C"; + base0F = "#B48EAD"; + }; }; config = { diff --git a/pkgs/applications/editors/neovim/nmasur/neovim/package.nix b/pkgs/applications/editors/neovim/nmasur/neovim/package.nix index 6871028..8119dc7 100644 --- a/pkgs/applications/editors/neovim/nmasur/neovim/package.nix +++ b/pkgs/applications/editors/neovim/nmasur/neovim/package.nix @@ -28,7 +28,7 @@ { pkgs, - colors ? (import ../../../../../../colorscheme/nord).dark, + colors ? null, terraform ? false, github ? false, kubernetes ? false, diff --git a/platforms/generators/aws/default.nix b/platforms/generators/aws/default.nix index 5507ae2..d33f6cd 100644 --- a/platforms/generators/aws/default.nix +++ b/platforms/generators/aws/default.nix @@ -14,17 +14,16 @@ in config = lib.mkIf cfg.enable { - # AWS settings require this - permitRootLogin = "prohibit-password"; + nmasur.presets.services.openssh-aws.enable = lib.mkDefault true; # Make sure disk size is large enough # https://github.com/nix-community/nixos-generators/issues/150 - amazonImage.sizeMB = 16 * 1024; + virtualisation.diskSize = lib.mkDefault (16 * 1024); # In MB - boot.kernelPackages = pkgs.legacyPackages.x86_64-linux.linuxKernel.packages.linux_6_6; - boot.loader.systemd-boot.enable = lib.mkForce false; - boot.loader.efi.canTouchEfiVariables = lib.mkForce false; - services.amazon-ssm-agent.enable = true; + boot.kernelPackages = lib.mkDefault pkgs.linuxKernel.packages.linux_6_6; + boot.loader.systemd-boot.enable = false; + boot.loader.efi.canTouchEfiVariables = false; + services.amazon-ssm-agent.enable = lib.mkDefault true; users.users.ssm-user.extraGroups = [ "wheel" ]; }; diff --git a/platforms/generators/default.nix b/platforms/generators/default.nix deleted file mode 100644 index a4303ca..0000000 --- a/platforms/generators/default.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ lib, ... }: -{ - imports = 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)) - ]; -} diff --git a/platforms/home-manager/default.nix b/platforms/home-manager/default.nix deleted file mode 100644 index a4303ca..0000000 --- a/platforms/home-manager/default.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ lib, ... }: -{ - imports = 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)) - ]; -} diff --git a/platforms/nix-darwin/default.nix b/platforms/nix-darwin/default.nix deleted file mode 100644 index a4303ca..0000000 --- a/platforms/nix-darwin/default.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ lib, ... }: -{ - imports = 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)) - ]; -} diff --git a/platforms/nixos/default.nix b/platforms/nixos/default.nix deleted file mode 100644 index a4303ca..0000000 --- a/platforms/nixos/default.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ lib, ... }: -{ - imports = 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)) - ]; -} diff --git a/platforms/nixos/modules/nmasur/presets/services/openssh-aws.nix b/platforms/nixos/modules/nmasur/presets/services/openssh-aws.nix new file mode 100644 index 0000000..111a9d4 --- /dev/null +++ b/platforms/nixos/modules/nmasur/presets/services/openssh-aws.nix @@ -0,0 +1,27 @@ +# SSHD settings for AWS machines + +{ + config, + lib, + ... +}: + +let + cfg = config.nmasur.presets.services.openssh-aws; +in +{ + + options.nmasur.presets.services.openssh-aws = { + enable = lib.mkEnableOption "OpenSSH on AWS VMs"; + }; + + config = lib.mkIf cfg.enable { + services.openssh = { + settings = { + # AWS settings require this + PermitRootLogin = lib.mkForce "prohibit-password"; + }; + }; + + }; +} diff --git a/platforms/nixos/modules/nmasur/profiles/base.nix b/platforms/nixos/modules/nmasur/profiles/base.nix index 3ae85b6..6129b85 100644 --- a/platforms/nixos/modules/nmasur/profiles/base.nix +++ b/platforms/nixos/modules/nmasur/profiles/base.nix @@ -52,19 +52,6 @@ in pkgs.curl ]; - # Include home-manager config in NixOS - home-manager = { - sharedModules = [ ../../../../home-manager ]; - - # Use the system-level nixpkgs instead of Home Manager's - useGlobalPkgs = lib.mkDefault true; - - # Install packages to /etc/profiles instead of ~/.nix-profile, useful when - # using multiple profiles for one user - useUserPackages = lib.mkDefault true; - - }; - # Extending time for home-manager build for things like nix-index cache systemd.services."home-manager-${username}" = { serviceConfig.TimeoutStartSec = lib.mkForce "45m";