Poetry2nix devShell: mkShell vs env.overrideAttrs

beautysh uses the following devShell:

devShell =
  let
    beautysh = pkgs.poetry2nix.mkPoetryEnv {
      python = pkgs.${pyLatest};
      projectDir = ./.;
      editablePackageSources.beautysh = ./beautysh;
    };
  in
  beautysh.env.overrideAttrs (old: {
    nativeBuildInputs = with pkgs; old.nativeBuildInputs ++ [
      nixpkgs-fmt
      poetry
    ];
  });
});

How does this differ from the implementation I see normally like the following:

devShell = pkgs.mkShell {
  buildInputs = with pkgs; [
    nixpkgs-fmt
    poetry
    (pkgs.poetry2nix.mkPoetryEnv {
      inherit python;
      projectDir = ./.;
      editablePackageSources = {
        my-app = ./src;
      };
    })
  ];
};

What is the advantage of overrideAttrs of the mkPoetryEnv instead of using mkShell?

overrideAttrs is used to specify external dependencies (non Python package) to a Poetry environment. This is documented here.

1 Like