Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I overlay packages system-wide? #183

Open
HPRIOR opened this issue Nov 30, 2024 · 0 comments
Open

How can I overlay packages system-wide? #183

HPRIOR opened this issue Nov 30, 2024 · 0 comments

Comments

@HPRIOR
Copy link

HPRIOR commented Nov 30, 2024

I would like to create project-level flakes which declares the relevant rust packages/tools to install, rather than this being declared system-wide.

I am having trouble getting this to work correctly with my system setup. My current working solution is also less than ideal.

I am using nixvim to install neovim and use the rust-analyzer lsp. This depends on rustc, cargo, rust-analyzer and the rust-src path. If I declare fenix rust packages in my project-level flake devshell, the rust packages used by nixvim can get out of sync, as nixvim will use standard rust packages from nixpkgs. This can cause all kinds of problems. For example, a slight difference in cargo versions would cause the build cache to be invalidated which completely broke incremental builds.

My current solution for keeping packages in sync is to create a attribute set like this:

  rust-packages = rec {
    toolchain-version = "stable";
    toolchain = pkgs.fenix.${toolchain-version}.withComponents [
      "cargo"
      "clippy"
      "rust-src"
      "rustc"
      "rustfmt"
    ];
    analyzer = pkgs.fenix.${toolchain-version}.rust-analyzer;
    src = pkgs.fenix.${toolchain-version}.rust-src;
    cargo = pkgs.fenix.${toolchain-version}.cargo;
    rustc = pkgs.fenix.${toolchain-version}.rustc;
  };

Use this set to install rust packages system-wide

    home.packages = with pkgs;
      [
        rust-packages.toolchain
        rust-packages.cargo
      ]

Then use the set when declaring my nixvim configuration

    servers = {
      rust-analyzer = {
        enable = true;
        package = rust-packages.analyzer;
        cargoPackage = rust-packages.cargo;
        rustcPackage = rust-packages.rustc;
        };
    };

This keeps my rust packages in sync, but it makes my devshells less reproducible; if I specify fenix overlays in a devshell, there is a hidden dependency on my nixvim configuration. If I want to change the version of the toolchain I would need to change my devshells and my nixvim configuration. Because of this, I just declare my rust tool chain system wide and remove any reference to rust in my devshells.

Is there a way to make all relevant rust packages in my system derive from the fenix overlay? I am currently trying to do this:

          home-manager.darwinModules.home-manager
          {
            nixpkgs.overlays = [
              fenix.overlays.default
              (final: prev: {
                rust-analyzer = prev.fenix.stable.rust-analyzer;
                rust-src = prev.fenix.stable.rust-src;
                rustc = prev.fenix.stable.rustc;
                cargo = prev.fenix.stable.cargo;
              })
            ];
          }

But it isn't working. I am getting an error that cargo doesn't have the expected overlay attribute. I'm assuming I'm using the overlay incorrectly here.

Any help would be appreciated. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant