summary refs log tree commit diff
path: root/pkgs/development/haskell-modules
diff options
context:
space:
mode:
authorGabriel Gonzalez <gabriel@awakenetworks.com>2018-07-03 09:25:15 -0700
committerGabriel Gonzalez <gabriel@awakenetworks.com>2018-07-03 09:25:15 -0700
commite57fd11bb4c74ac858184611240f295ab7043d52 (patch)
tree77ce832416130db70383613f8c789857e5778b9e /pkgs/development/haskell-modules
parent208091b31bcb15d948e2141460953e6f0ea08f5e (diff)
downloadnixlib-e57fd11bb4c74ac858184611240f295ab7043d52.tar
nixlib-e57fd11bb4c74ac858184611240f295ab7043d52.tar.gz
nixlib-e57fd11bb4c74ac858184611240f295ab7043d52.tar.bz2
nixlib-e57fd11bb4c74ac858184611240f295ab7043d52.tar.lz
nixlib-e57fd11bb4c74ac858184611240f295ab7043d52.tar.xz
nixlib-e57fd11bb4c74ac858184611240f295ab7043d52.tar.zst
nixlib-e57fd11bb4c74ac858184611240f295ab7043d52.zip
Add `pkgs.haskell.lib.readDirectory` utility
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
Diffstat (limited to 'pkgs/development/haskell-modules')
-rw-r--r--pkgs/development/haskell-modules/lib.nix19
1 files changed, 19 insertions, 0 deletions
diff --git a/pkgs/development/haskell-modules/lib.nix b/pkgs/development/haskell-modules/lib.nix
index fb1302f60ea5..8a5ed7d4e948 100644
--- a/pkgs/development/haskell-modules/lib.nix
+++ b/pkgs/development/haskell-modules/lib.nix
@@ -382,4 +382,23 @@ rec {
           allPkgconfigDepends;
       };
 
+  # Utility to convert a directory full of `cabal2nix`-generated files into a
+  # package override set
+  #
+  # readDirectory : Directory -> HaskellPackageOverrideSet
+  readDirectory =
+    directory:
+
+    self: super:
+      let
+        haskellPaths = builtins.attrNames (builtins.readDir directory);
+
+        toKeyVal = file: {
+          name  = builtins.replaceStrings [ ".nix" ] [ "" ] file;
+
+          value = self.callPackage (directory + "/${file}") { };
+        };
+
+      in
+        builtins.listToAttrs (map toKeyVal haskellPaths);
 }