Skip to content

haskell-nix.extraPkgconfigMappings documentation #1670

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion docs/tutorials/pkg-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ nixpkgs.overlays = [
];
```

The user can map package(s) in Nixpkgs to a `pkgconfig-depends` name by
overlaying the `haskell-nix.extraPkgconfigMappings` attribute:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: @yvan-sraka

Should we document that directly on the https://input-output-hk.github.io/haskell.nix/ manual?

I added this to the "Nixpkgs overlay" section of this tutorial since it also uses overlays. I guess it's more specifically a haskell-nix overlay, but still 🤔


```nix
nixpkgs.overlays = [
(self: super: {
haskell-nix = super.haskell-nix // {
extraPkgconfigMappings = super.haskell-nix.extraPkgconfigMappings // {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to take care to not clobber other overlays that add mappings.

I have some helpers in my Nix code since this gets tedious:

{
    # See https://stackoverflow.com/a/54505212
    recursiveMerge = x: y: recursiveMergeAll [x y];
    recursiveMergeAll = attrList:
      with super.lib;
      let f = attrPath:
            zipAttrsWith (n: values:
              if tail values == []
              then head values
              else if all isList values
              then unique (concatLists values)
              else if all isAttrs values
              then f (attrPath ++ [n]) values
              else last values
            );
      in f [] attrList;

    mapExtraPkgconfig = super-haskell-nix: name: mappings: recursiveMerge super-haskell-nix {
      extraPkgconfigMappings = { "${name}" = mappings; };
    };
}

So my extraPkgconfigMappings overlays end up looking like this:

self: super:
{
  haskell-nix = super.macaroniLib.mapExtraPkgconfig super.haskell-nix "freeglut" ["freeglut"];
}

# String pkgconfig-depends names are mapped to lists of Nixpkgs
# package names
"SDL_gpu" = [ "SDL_gpu" ];
};
};
})
];
```

### Replace libraries of components

If a component is missing a dependency it can be added via modules. For example:
Expand Down Expand Up @@ -59,7 +76,7 @@ the Haskell.nix sources, so that it's solved for all users.
— for `build-tool-depends`, `frameworks`, `extra-libraries`, etc.

Each name can be mapped to:
1. A single package from nixkpgs.
1. A single package from nixpkgs.
2. `null` — eliminates the dependency
3. A list of packages — sometimes needed for dependencies such as `X11`.

Expand Down
2 changes: 1 addition & 1 deletion overlays/haskell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final: prev: {
# overlays.
defaultModules = [];

# TODO: doc etc
# Additional user-provided mappings to augment ./../lib/pkgconf-nixpkgs-map.nix
extraPkgconfigMappings = {};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: @L-as

This should probably be part of the project-common module.

What did you mean by this? I'm not familiar with the whole structure of haskell.nix, but would that also make it easy to set these options globally?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramirez7 Sorry for the late response, yeah, essentially you add an option for it in modules/project-common.nix, then it's in the result of evaluating the module (see cabalProject') .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    extraPkgconfigMappings = mkOption {
      type = submodule [ fill this out ];
      default = {};
      description = ''
        Extra pkgconfig mappings
      '';
    };

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm I'll try this in a branch and get a good comparison going

# Nix Flake based source pins.
# To update all inputs, get unstable Nix and then `nix flake update --recreate-lock-file`
Expand Down