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?
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";
})
];
};