{ inputs, flake, self }: let
  overlays = with inputs; [ 
    (import rust-overlay) 
    util.overlays.default
    cargo2nix.overlays.default
  ];
  pkgs-unstable = system: import inputs.nixpkgs-unstable { inherit system overlays; };
in rec {
  composedOverlays = overlays;
  nixpkgs-lib = inputs.nixpkgs.lib;
  rustVersion = "1.88.0";
  rustToolchain = system: (pkgs-unstable system).pkgsBuildHost.rust-bin.stable."${rustVersion}".default.override {
    targets = [ "wasm32-unknown-unknown" ];
  };
  forDomains = lib: domains: func: lib.mkMerge (map func domains);
  commonHttpConfig = ''
    # Custom log format for detailed access logs
    log_format detailed '$remote_addr - $remote_user [$time_local] '
                        '"$request" $status $body_bytes_sent '
                        '"$http_referer" "$http_user_agent" '
                        'rt=$request_time uct="$upstream_connect_time" '
                        'uht="$upstream_header_time" urt="$upstream_response_time" '
                        'cs=$upstream_cache_status '
                        'host="$host" '
                        'request_id="$request_id" '
                        'request_body="$request_body"';

    # Custom log format specifically for debugging 404s
    log_format debug_404 '$remote_addr - $remote_user [$time_local] '
                         '"$request" $status $body_bytes_sent '
                         '"$http_referer" "$http_user_agent" '
                         'host="$host" '
                         'uri="$uri" '
                         'request_uri="$request_uri" '
                         'args="$args" '
                         'document_root="$document_root" '
                         'request_filename="$request_filename" '
                         'fastcgi_script_name="$fastcgi_script_name"';

    # Set up conditional logging for 404 errors
    map $status $is_404 {
      default 0;
      404 1;
    }
  '';
}
