haskell.nix icon indicating copy to clipboard operation
haskell.nix copied to clipboard

Is it possible to gather all licenses for the dependencies of a given component?

Open thomasjm opened this issue 5 years ago • 7 comments

There's a passing reference to license gathering in the "motivation" section of the documentation but I can't find anything else on it.

I poked around in nix repl and it seemed like this should be straightforward but I couldn't quite figure it out. I'm hoping for something along the lines of the stack ls dependencies --license command. Thanks!

thomasjm avatar Aug 10 '20 02:08 thomasjm

To answer my own question, I've written a function to generate a nice YAML file of dependencies and licenses like this:

let

  pkgSetToLicenseFile = filename: pkgSet:
    let licenseFn = (k: v: if k == "base" || k == "ghc-heap" then "" else v.package.license);
        nameToLicense = lib.generators.toJSON {} (lib.mapAttrs licenseFn pkgSet);
    in
      runCommand filename { buildInputs = [yq-go]; } ''
        yq r --prettyPrint ${writeText "temp.yaml" nameToLicense} > $out
      '';

in

pkgSetToLicenseFile "licenses.yaml" my-project.components.exes.my-executable.project.pkg-set.config.packages;

Note how I had to ignore base and ghc-heap, in order to avoid a Nix error like "getting status of .../base.nix: No such file or directory".

Hopefully using .project.pkg-set.config.packages like this is picking up the right dependencies...

thomasjm avatar Oct 26 '20 09:10 thomasjm

Actually no, it seems to be actually grabbing all dependencies in the Stackage snapshot. Back to the drawing board...

thomasjm avatar Oct 26 '20 09:10 thomasjm

Aha, it seems mapping over the component's buildInputs gets the dependencies I want. I wrote a function like this to generate a map from dependency name to license:

componentToLicenseMap = component: 
  lib.listToAttrs (map (x: lib.nameValuePair x.identifier.name x.meta.license) component.buildInputs);

thomasjm avatar Oct 26 '20 10:10 thomasjm

I think something like this should be in haskell.nix, ideally for the whole project.

michaelpj avatar Nov 24 '23 10:11 michaelpj

We might also want something like an allowedLicenses/disallowedLicenses predicate to cabalProject, in order to enforce a policy.

michaelpj avatar Nov 24 '23 10:11 michaelpj

Ideas:

  • A function that takes a component and produces a dependency-pkgid -> license map (or tree?)
  • A function that processes the output of that making an assertion on the licenses

Then you can more-or-less roll your own by just mapping over your project components. But we might want something that goes all the way up to cabalProject to make this as easy as possible.

michaelpj avatar Nov 24 '23 10:11 michaelpj

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Mar 23 '24 16:03 stale[bot]