cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
3.56k stars 259 forks source link

Support local overlays #478

Open fzakaria opened 1 year ago

fzakaria commented 1 year ago

Would be great to support local overlays in the repository.

I have to override a package that depends on another package etc.. and doing it with an overlay is very simple.

My workaround at the moment is:

  overlay = final: prev: { f = final.firefox; };
  pkgs1 = pkgs.extend overlay;

and I have to use pkgs1 everywhere.

fzakaria commented 1 year ago

My other option was doing all the chaining myself

  let sqlite-3411 = pkgs.sqlite.overrideAttrs (oldAttrs: rec {
      version = "3.41.1";
      src = pkgs.fetchurl {
        url = "https://sqlite.org/2023/sqlite-autoconf-3410100.tar.gz";
        sha256 = "sha256-Ta376rn44WxpXU+7xRwWsvd/uX/0wcPROZGd/AOMnjM=";
      };
    });
  pythonPackageOverrides = self: super: {
      apsw = super.apsw.overridePythonAttrs (oldAttrs: rec {
      version = "3.41.0.0";
      src = pkgs.fetchFromGitHub {
        owner = "rogerbinns";
        repo = "apsw";
        rev = "refs/tags/${version}";
        sha256 = "sha256-U7NhC83wBaUONLsQbL+j9866u4zs58O6AQxwzS3e0qM=";
      };
      buildInputs = [
        sqlite-3411
      ];
    });
  };
in {

in my devenv.nix

domenkozar commented 1 year ago

I was thinking to add overlays to devenv.yaml to support this one.

knarkzel commented 1 year ago

This feature is necessary for me to use devenv instead of manual flake.nix :smile:

domenkozar commented 9 months ago

You can do this using devenv.yaml:

inputs:
  subflake:
    url: path:./subflake
    overlays:
      - default

and in subflake/flake.nix:

{
  outputs = { ... }: {
    overlays.default = self: super: {
      hello2 = self.hello;
    };
  };
}

Then your devenv.nix can be:

{ pkgs, ... }: {
  packages = [ pkgs.hello2 ];
}
domenkozar commented 9 months ago

To avoid that boilerplate we could support devenv.yaml like:

overlays:
- myoverlay1: | 
    self: super: { hello2 = self.hello; }
- ./myoverlay2.nix
domenkozar commented 2 weeks ago

Another possibility would be to evaluate pkgs twice, to add extra overlays.

This would provide a better API (allowing us to provide overlays per module) for sacrificing performance (to be measured how much).

domenkozar commented 2 weeks ago

Relevant is #792 because we need to import nixpkgs once.