How to install packages related only to dev

On my flake.nix I use Mailhog in order to catch emails when developing locally. However, I don’t need it when deploying code. Same for hspec and a bunch of other dev-related packages.

How to declare it only for dev, and have it included only if executed via devenv up?

Maybe it’s also a wider question of howto define multiple server envs (e.g. DEV, TEST, LIVE).
Maybe there should be separate flake.nix files?

How to declare it only for dev, and have it included only if executed via devenv up ?

I think it should already work if you do e.g.:

                devenv.shells.default = {
                    services.mailhog.enable = true;

BUT skip the packages = with pkgs; [ mailhog ] part in the flake.nix.

Maybe it’s also a wider question of howto define multiple server envs (e.g. DEV, TEST, LIVE).
Maybe there should be separate flake.nix files?

Multiple servers can be declared by adding more flake.nixosConfigurations."ihp-app" = nixpkgs.lib.nixosSystem { declarations, e.g.

flake.nixosConfigurations."server-a" = nixpkgs.lib.nixosSystem { ... }
flake.nixosConfigurations."server-b" = nixpkgs.lib.nixosSystem { ... }

To avoid duplication you can extract out code to a file:

            flake.nixosConfigurations."server-a" = nixpkgs.lib.nixosSystem {
                system = "x86_64-linux";
                specialArgs = inputs;
                modules = [
                    "${nixpkgs}/nixos/modules/virtualisation/amazon-image.nix"
                    ihp.nixosModules.app
                    ./Config/nix/server-a.nix
                ];
            };

Then the server-a.nix can look like this:

{ config, pkgs, modulesPath, lib, self, migrate, migrations, ... }:
{
    services.ihp = ...
}   

Mailhog part works :+1:

To avoid duplication you can extract out code to a file:

Here we have an example of some data that will be used for all servers, and nv name, AWS keys etc will not be shared. How would you structure the nix files to avoid duplication/ allow overriding?

            # Adding the new NixOS configuration for "qa"
            # Used to deploy the IHP application to AWS.
            #
            # Change the `CHANGE-ME` to your correct config.
            flake.nixosConfigurations."qa" = nixpkgs.lib.nixosSystem {
                system = "x86_64-linux";
                specialArgs = inputs;
                modules = [
                    "${nixpkgs}/nixos/modules/virtualisation/amazon-image.nix"
                    ihp.nixosModules.appWithPostgres
                    ({ lib, pkgs, ... }: {

                        networking.firewall = {
                            enable = true;
                            allowedTCPPorts = [ 22 80 443 8000 ];
                        };

                        # Enable the Let's encrypt certificate
                        security.acme.defaults.email = "CHANGE-ME@example.com";

                        # Accept the terms of service of the Let's encrypt provider.
                        security.acme.acceptTerms = true;

                        services.nginx = {
                            virtualHosts."CHANGE-ME.com" =  {
                                # Uncomment to have http auth with username `foo` and password `bar`.
                                # basicAuth = { foo = "bar"; };
                            };
                        };

                        services.ihp = {
                            domain = "CHANGE-ME.com";
                            migrations = ./Application/Migration;
                            schema = ./Application/Schema.sql;
                            fixtures = ./Application/Fixtures.sql;
                            sessionSecret = "CHANGE-ME";
                            additionalEnvVars = {
                                # Indicate the environment name, e.g. "production", "staging", "qa".
                                ENV_NAME = "qa";

                                # Uncomment to use a custom database URL
                                # DATABASE_URL = "postgresql://postgres:...CHANGE-ME";

                                SMTP_HOST = "email-smtp.eu-west-1.amazonaws.com";
                                SMTP_PORT = "587";
                                SMTP_ENCRYPTION = "STARTTLS";

                                SMTP_USER = "CHANGE-ME";
                                SMTP_PASSWORD = "CHANGE-ME";

                                AWS_ACCESS_KEY_ID = "CHANGE-ME";
                                AWS_SECRET_ACCESS_KEY = "CHANGE-ME";
                            };
                        };

                        # Keep as is.
                        system.stateVersion = "23.05";
                    })
                ];
            };