{
  description = "Rust ASH test rust configuration";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    rust-overlay = {
      url = "github:oxalica/rust-overlay";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixgl = {
      # Revert this to community version when https://github.com/nix-community/nixGL/pull/187 is merged
      url = "github:phirsch/nixGL/fix-versionMatch";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.flake-utils.follows = "flake-utils";
    };
  };

  outputs = { self, nixpkgs, flake-utils, rust-overlay, nixgl }:
    flake-utils.lib.eachSystem flake-utils.lib.allSystems (system:
      let
        overlays = [ (import rust-overlay) nixgl.overlay ];
        pkgs = import nixpkgs {
          inherit system overlays;
          config.allowUnfree = true;
        };
        rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;

        rustPlatform = pkgs.recurseIntoAttrs (pkgs.makeRustPlatform {
          rustc = rust;
          cargo = rust;
        });

        renderdoc = pkgs.renderdoc.overrideAttrs (oldAttrs: {
          cmakeFlags = oldAttrs.cmakeFlags ++ [
            (pkgs.lib.cmakeBool "ENABLE_UNSUPPORTED_EXPERIMENTAL_POSSIBLY_BROKEN_WAYLAND" true)
          ];
        });

        buildInputs = with pkgs; [ vulkan-headers vulkan-loader vulkan-validation-layers renderdoc ]
          ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isLinux (with pkgs; [
          stdenv.cc.cc.lib

          # Wayland
          libxkbcommon
          wayland
          libGL
          # Xorg
          xorg.libX11
          xorg.libXcursor
          xorg.libXi
          xorg.libxcb
          xorg.libxshmfence
        ])
          ++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin (with pkgs; [ darwin.apple_sdk.frameworks.SystemConfiguration ]);

        nativeBuildInputs = with pkgs; [
          pkg-config
          cmake
          python312
        ];

        mkCustomShell = { packages ? [ ] }: pkgs.mkShell {
          nativeBuildInputs = [
            renderdoc
            (rust.override { extensions = [ "rust-src" "rust-analyzer" ]; })
          ] ++ nativeBuildInputs;

          buildInputs = buildInputs
            ++ packages;

          LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
          VK_LAYER_PATH = "${pkgs.vulkan-validation-layers}/share/vulkan/explicit_layer.d:${renderdoc}/share/vulkan/implicit_layer.d";
          RUST_LOG = "info,rust_vulkan_test=trace";
        };
      in
      {
        devShells = {
          default = mkCustomShell { packages = [ pkgs.nixgl.auto.nixVulkanNvidia pkgs.nixgl.nixVulkanMesa ]; };
          nixos = mkCustomShell { };
        };

        packages = {
          default = rustPlatform.buildRustPackage {
            pname = "rust_ash_test";
            version = "0.1.0";

            src = self;

            inherit nativeBuildInputs buildInputs;

            cargoLock = {
              lockFile = ./Cargo.lock;
            };
          };
        };
      });
}