{
  description = "NSV I2C env";

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

  outputs = { self, nixpkgs }:
    let
      system = "x86_64-linux";
      pkgs = nixpkgs.legacyPackages.${system};

      python = pkgs.python311;
      python-env = python.withPackages(ps: [
        (ps.buildPythonPackage rec {
          pname = "vunit-hdl";
          version = "4.7.0";
          src = pkgs.fetchFromGitHub {
            owner = "VUnit";
            repo = "vunit";
            rev = "v4.7.0";
            hash = "sha256-xhCPPnUXUdLg5kElbyJKW0tJOZMUoM1bV2siOsoz3Zs=";
          };

          doCheck = false;

          nativeBuildInputs = [
            ps.setuptoolsBuildHook
            ps.setuptools
            ps.pythonImportsCheckHook

            pkgs.ghdl # VHDL simulator needed for build/testing
            ps.pytest
          ];

          propagatedBuildInputs = [
            ps.colorama
          ];
        })
      ]);
      vhdl-toolchain = pkgs.symlinkJoin {
        name = "vhdl-toolchain";
        meta.mainProgram = "nvc";
        paths = [
          pkgs.ghdl
          pkgs.nvc
        ];
      };
    in {
      packages.${system}.default = vhdl-toolchain;

      devShells.${system} = {
        docs = pkgs.mkShell {
          packages =  let
            pandoc-latex-environment = pkgs.stdenv.mkDerivation rec {
              pname = "pandoc_latex_environment";
              version = "1.1.6.2";

              src = pkgs.fetchPypi {
                inherit pname version;
                hash = "sha256-61L0oYzXRFHMgTmWRJtCuqGDzaqhQfaQEBsCp7Rx+5c=";
              };

              installPhase = ''
                install -Dm755 pandoc_latex_environment.py $out/bin/pandoc-latex-environment
              '';

              propagatedBuildInputs = [
                (pkgs.python3.withPackages(ps: [
                  ps.panflute
                ]))
              ];
            };
        in [
            pkgs.pandoc
            pkgs.tectonic
            pkgs.inkscape
            (pkgs.python3.withPackages(ps: [
              ps.pandocfilters
            ]))
            pandoc-latex-environment
          ];
        };

        default = pkgs.mkShell rec {
          packages = [
            vhdl-toolchain

            (pkgs.rustPlatform.buildRustPackage rec {
                pname = "vhdl-ls";
                version = "0.81.0";

                src = pkgs.fetchFromGitHub {
                  owner = "VHDL-LS";
                  repo = "rust_hdl";
                  rev = "348e42da73fc1d5b3ac2ed51f6d056a7af46d171";
                  hash = "sha256-F8LQijA7XcZyGipd0gG7SOQro38iltSmDGSWtbu6Umc=";
                };

                cargoHash = "sha256-hkmaMzeQLd3l6A3xyLAZk+MrEeUKPd7H2N4Nsz7nBmk=";

                postPatch = ''
                  substituteInPlace vhdl_lang/src/config.rs \
                    --replace /usr/lib $out/lib
                '';

                postInstall = ''
                  mkdir -p $out/lib/rust_hdl
                  cp -r vhdl_libraries $out/lib/rust_hdl
                '';
            })
            pkgs.gtkwave
            python-env
          ];

          PYTHON_SITE_PACKAGES = "${python-env}/${python.sitePackages}";
          VUNIT_VHDL_LIB = "${PYTHON_SITE_PACKAGES}/vunit/vhdl";

          shellHook = ''
            ln -s ${VUNIT_VHDL_LIB} ./libs/vunit
          '';

          VUNIT_SIMULATOR = "nvc";
        };
      };
    };
}
