Skip to content

Overriding pkgs used by tools does not work when using flake-parts integration #204

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

Closed
terlar opened this issue Dec 1, 2022 · 3 comments

Comments

@terlar
Copy link
Contributor

terlar commented Dec 1, 2022

I have made a test via the template and found that the pkgs override is not working and not used by the tools.

Define this flake.nix file:

{
  inputs = {
    flake-parts.url = "github:hercules-ci/flake-parts";
    flake-parts.inputs.nixpkgs.follows = "nixpkgs";
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    pre-commit-hooks-nix.url = "github:hercules-ci/pre-commit-hooks.nix/flakeModule";
    pre-commit-hooks-nix.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = inputs@{ self, flake-parts, ... }:
    flake-parts.lib.mkFlake
      { inherit self; }
      {
        imports = [
          inputs.pre-commit-hooks-nix.flakeModule
        ];
        systems = [ "x86_64-linux" "aarch64-darwin" ];
        perSystem = { config, pkgs, ... }: {
          packages.hello = pkgs.hello;
          pre-commit = {
            check.enable = true;
            pkgs = pkgs // {
              nixpkgs-fmt = pkgs.writeShellApplication {
                name = "nixpkgs-fmt";
                text = "false";
              };
            };
            settings.hooks.nixpkgs-fmt.enable = true;
          };
          devShells.default = pkgs.mkShell {
            shellHook = ''
              ${config.pre-commit.installationScript}
              echo 1>&2 "Welcome to the development shell!"
            '';
          };
        };
      };
}

Run nix flake check

During this experiment I found out that the overridden pkgs is used for parts of pre-commit-hooks.nix, but not for the actual tools. For example this worked, but shouldn't:

...
          pre-commit = {
            check.enable = true;
            pkgs = { inherit (pkgs) runCommand pre-commit jq lib callPackage git; };
            settings.hooks.nixpkgs-fmt.enable = true;
          };
...
@terlar terlar changed the title Overriding pkgs used by tools does not work when used via flake-parts Overriding pkgs used by tools does not work when using flake-parts integration Dec 1, 2022
@roberth
Copy link
Contributor

roberth commented Dec 1, 2022

pre-commit-hooks.nix uses callPackage in call-tools.nix. callPackage is unaware of anything you do with pkgs // but does support overlays. Does the problem occur with the following change?

-            pkgs = pkgs // {
+            pkgs = pkgs.extend (final: prev: {

@terlar
Copy link
Contributor Author

terlar commented Dec 1, 2022

You are right, I got tripped up by the empty object with explicit attributes, didn’t reflect on passing in callPackage and what that entails. Thank you for pointing out this oversight. Would this be the recommended way if one would need to override a tool?

@terlar terlar closed this as completed Dec 1, 2022
@roberth
Copy link
Contributor

roberth commented Dec 2, 2022

Would this be the recommended way if one would need to override a tool?

Extending nixpkgs has a significant evaluation performance cost, so another way would be preferable. Adding to #196...

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

2 participants