{
  description = "aprs.me - Phoenix LiveView APRS packet mapping platform";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

    flake-parts = {
      url = "github:hercules-ci/flake-parts";
      inputs.nixpkgs-lib.follows = "nixpkgs";
    };

    systems.url = "github:nix-systems/default";

    pre-commit-hooks = {
      url = "github:cachix/pre-commit-hooks.nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs =
    inputs@{
      self,
      nixpkgs,
      flake-parts,
      systems,
      pre-commit-hooks,
    }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      # nixpkgs 26.11 dropped x86_64-darwin support
      systems = builtins.filter (s: s != "x86_64-darwin") (import systems);

      perSystem =
        {
          config,
          self',
          inputs',
          pkgs,
          system,
          ...
        }:
        {
          _module.args.pkgs = import nixpkgs {
            inherit system;
            overlays = [
              # Pin specific Elixir and Erlang versions to match .tool-versions
              # Elixir 1.20.2-otp-29, Erlang 29.0.1
              (final: prev: {
                # Use Erlang 29 — no top-level erlang_29 yet, use beam.interpreters
                erlang = prev.beam.interpreters.erlang_29;

                # Use Elixir 1.20 with Erlang 29 (1.20.2-otp-29)
                elixir = prev.beam.packages.erlang_29.elixir_1_20;

                # Ensure beam packages use our pinned versions
                beamPackages = prev.beam.packages.erlang_29.extend (
                  self: super: {
                    elixir = super.elixir_1_20;
                  }
                );
              })
            ];
          };

          # Development shell with PostgreSQL (PostGIS), LSPs, formatters
          devShells.default = pkgs.callPackage ./nix/shell.nix {
            pre-commit-hooks = inputs.pre-commit-hooks.lib.${system};
          };

          # Nix formatter for flake files
          formatter = pkgs.nixfmt;
        };
    };
}
