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

Add pkgs.haskell.lib.packagesFromDirectory utility #42923

Merged
merged 5 commits into from Jul 10, 2018

Conversation

Gabriella439
Copy link
Contributor

Motivation for this change

This adds a readDirectory utility that can be used to "slurp" a directory
full of cabal2nix-generated files and transform them into a Haskell package
override set. The main use of this is so that users don't have to write:

{ overrides = self: super: {
    foo = self.callPackage ./path/to/foo.nix { };

    bar = self.callPackage ./path/to/bar.nix { };

    ...
  };
}

Instead, they can write:

{ overrides = pkgs.haskell.lib.readDirectory ./path/to;
}

This is a an alternative to packageSourceOverrides which primarily addresses
the following use cases:

  • The desired package is not yet available in all-cabal-hashes (perhaps the
    user is pinned to an older revision of nixpkgs)
  • The default cabal2nix invocation used by packageSourceOverrides
    does not use the desired cabal2nix flags
  • The user wants to avoid the use of import-from-derivation
Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

This adds a `readDirectory` utility that can be used to "slurp" a directory
full of `cabal2nix`-generated files and transform them into a Haskell package
override set.  The main use of this is so that users don't have to write:

```
{ overrides = self: super: {
    foo = self.callPackage ./path/to/foo.nix { };

    bar = self.callPackage ./path/to/bar.nix { };

    ...
  };
}
```

Instead, they can write:

```
{ overrides = pkgs.haskell.lib.readDirectory ./path/to;
}
```

This is a an alternative to `packageSourceOverrides` which primarily addresses
the following use cases:

* The desired package is not yet available in `all-cabal-hashes` (perhaps the
  user is pinned to an older revision of `nixpkgs`)
* The default `cabal2nix` invocation used by `packageSourceOverrides`
  does not use the desired `cabal2nix` flags
* The user wants to avoid the use of import-from-derivation
@roberth
Copy link
Member

roberth commented Jul 3, 2018

It'd be nice to ignore missing ${name}/${name}.nix files, so you can have your packages at the base of your megarepo. Maybe that functionality should be behind a predicate function taking names though.

If you make the first parameter an attrset pattern, such functionality can be added in the future. Future example:

{ directory, ignoreMissing ? false }:

@Gabriella439
Copy link
Contributor Author

@roberth: It's lazy, so it will only attempt to read files if you try to access the corresponding attribute and ignore any other files

However, I agree that it should probably take an attribute set as an argument for ease of extension later

@roberth
Copy link
Member

roberth commented Jul 3, 2018

@Gabriel439 good point. I'm using a little hack to collect self-defined attributes in my overlay for release.nix, which causes release.nix to be strict in all overlay attributes. I guess it is somewhat unlikely that others do the same because ... the hack relies on laziness. I should write about it :)

@roberth
Copy link
Member

roberth commented Jul 4, 2018

Not sure if readDirectory is sufficiently descriptive. What about packagesFromDirectory?

@roberth roberth changed the title Add pkgs.haskell.lib.readDirectory utility Add pkgs.haskell.lib.packagesFromDirectory utility Jul 6, 2018
Add `...` for less painful downgrades in the future
@roberth
Copy link
Member

roberth commented Jul 6, 2018

I've added ... for better compatibility.

LGTM. Will merge in a couple of days unless anyone objects.

@roberth roberth merged commit 873465e into NixOS:master Jul 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants