{
  description = "AIC8800 USB Wi-Fi driver for Linux";

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

  outputs = { self, nixpkgs }:
    let
      supportedSystems = [ "x86_64-linux" "aarch64-linux" ];
      forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
    in
    {
      packages = forAllSystems (system:
        let
          pkgs = import nixpkgs { inherit system; };
        in
        {
          aic8800-firmware = pkgs.stdenvNoCC.mkDerivation {
            pname = "aic8800-firmware";
            version = "2022-12-19";
            src = ./.;

            installPhase = ''
              runHook preInstall
              mkdir -p $out/lib/firmware
              cp -r usr/src/AIC8800/fw/aic8800D80 $out/lib/firmware/
              runHook postInstall
            '';

            meta = with pkgs.lib; {
              description = "Firmware blobs for AIC8800 USB adapters";
              license = licenses.unfreeRedistributableFirmware;
              platforms = platforms.linux;
            };
          };
        }
      );

      nixosModules = {
        default = { config, lib, pkgs, ... }: import ./nixos-module.nix {
          inherit config lib pkgs;
          aic8800-src = self;
        };
        aic8800 = { config, lib, pkgs, ... }: import ./nixos-module.nix {
          inherit config lib pkgs;
          aic8800-src = self;
        };
      };

      overlays = {
        default = final: prev: {
          aic8800-firmware = self.packages.${prev.system}.aic8800-firmware;
        };
      };
    };
}

