{
  description = "Emacs with MPS support";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    emacs-overlay.url = "github:nix-community/emacs-overlay";
  };

  outputs = { self, nixpkgs, emacs-overlay }:
    let
      system = "x86_64-linux";
      pkgs = import nixpkgs {
        inherit system;
        overlays = [ emacs-overlay.overlay ];
      };
      emacs-igc = pkgs.callPackage ({ emacs-git, mps }:
        emacs-git.overrideAttrs (old: {
          name = "emacs-git-mps";

          src = pkgs.fetchFromGitHub {
            owner = "emacs-mirror";
            repo = "emacs";
            rev = "feature/igc";
            sha256 = "sha256-QZBE2H5S9bbPGyIY9FDse9fSQHllGq+OlvssGs9DXmw=";
          };

          buildInputs = old.buildInputs ++ [ mps ];

          configureFlags = old.configureFlags ++ [
            "--disable-build-details"
            "--with-modules"
            "--with-x-toolkit=lucid"
            "--with-cairo"
            "--with-xft"
            "--with-sqlite3=yes"
            "--with-compress-install"
            "--with-toolkit-scroll-bars"
            "--with-native-compilation"
            "--without-imagemagick"
            "--with-mailutils"
            "--with-small-ja-dic"
            "--with-tree-sitter"
            "--with-xinput2"
            "--without-xwidgets"
            "--with-dbus"
            "--with-selinux"
            "--with-mps=yes"
          ];
        })
      ) {};
    in {
      packages.${system} = {
        emacs-igc-loaded = (pkgs.emacsPackagesFor emacs-igc).emacsWithPackages (
          epkgs: with epkgs;
            [
              nix-mode nix-modeline
              vterm jinx
              org-roam org-roam-ui
              pdf-tools notmuch
              magit forge orgit-forge
              treesit-grammars.with-all-grammars
            ]);
        
        default = self.packages.${system}.emacs-igc-loaded;
      };

      devShells.${system}.default = pkgs.mkShell {
          buildInputs = [ self.packages.${system}.emacs-igc-loaded ];
        };
    };
}