Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/cabal2nix
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2cc4e8a1a090
Choose a base ref
...
head repository: NixOS/cabal2nix
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c348f6f8d9ce
Choose a head ref
  • 2 commits
  • 361 files changed
  • 2 contributors

Commits on Jan 19, 2021

  1. Use lib instead of stdenv.lib

    On Nixpkgs, the work[1] for deprecating stdenv.lib has started.
    This patch updates the generator, existing documentation and tests to
    use the top-level lib attribute to access the standard library, instead
    of stdenv.lib.
    
    [1]: NixOS/nixpkgs#108938
    rnhmjoj committed Jan 19, 2021

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    rnhmjoj Michele Guerini Rocco
    Copy the full SHA
    683624d View commit details
  2. Merge pull request #477 from rnhmjoj/master

    Use lib instead of stdenv.lib
    peti authored Jan 19, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c348f6f View commit details
Showing 361 changed files with 1,001 additions and 1,024 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -10,15 +10,15 @@ Cabal2nix
For example:

$ cabal2nix cabal://mtl
{ mkDerivation, base, stdenv, transformers }:
{ mkDerivation, base, lib, transformers }:
mkDerivation {
pname = "mtl";
version = "2.2.1";
sha256 = "1icdbj2rshzn0m1zz5wa7v3xvkf6qw811p4s7jgqwvx1ydwrvrfa";
libraryHaskellDepends = [ base transformers ];
homepage = "http://github.com/ekmett/mtl";
description = "Monad classes, using functional dependencies";
license = stdenv.lib.licenses.bsd3;
license = lib.licenses.bsd3;
}

Cabal files can be referred to using the magic URL `cabal://NAME-VERSION`,
@@ -40,15 +40,15 @@ project on the local file system:

$ cabal get mtl-2.2.1 && cd mtl-2.2.1
$ cabal2nix .
{ mkDerivation, base, stdenv, transformers }:
{ mkDerivation, base, lib, transformers }:
mkDerivation {
pname = "mtl";
version = "2.2.1";
src = ./.;
libraryHaskellDepends = [ base transformers ];
homepage = "http://github.com/ekmett/mtl";
description = "Monad classes, using functional dependencies";
license = stdenv.lib.licenses.bsd3;
license = lib.licenses.bsd3;
}

This derivation will not fetch from hackage, but instead use the directory which
20 changes: 10 additions & 10 deletions doc/01-use-function-application-to-escape-override-hell.md
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ defines builds for versions 0.3.13, 0.4.0, and 0.4.1. Those definitions look
all quite similar, so we'll omit the third definition for brevity:

"hslua_0_3_13" = callPackage
({ mkDerivation, base, lua5_1, mtl }:
({ mkDerivation, base, lib, lua5_1, mtl }:
mkDerivation {
pname = "hslua";
version = "0.3.13";
@@ -70,13 +70,13 @@ all quite similar, so we'll omit the third definition for brevity:
libraryPkgconfigDepends = [ lua5_1 ];
testHaskellDepends = [ base ];
description = "A Lua language interpreter embedding in Haskell";
license = stdenv.lib.licenses.mit;
hydraPlatforms = stdenv.lib.platforms.none;
license = lib.licenses.mit;
hydraPlatforms = lib.platforms.none;
}) { inherit (pkgs) lua5_1; };

"hslua" = callPackage
({ mkDerivation, base, bytestring, hspec, hspec-contrib, HUnit
, lua5_1, QuickCheck, quickcheck-instances, text
, lib, lua5_1, QuickCheck, quickcheck-instances, text
}:
mkDerivation {
pname = "hslua";
@@ -90,7 +90,7 @@ all quite similar, so we'll omit the third definition for brevity:
quickcheck-instances text
];
description = "A Lua language interpreter embedding in Haskell";
license = stdenv.lib.licenses.mit;
license = lib.licenses.mit;
}) { inherit (pkgs) lua5_1; };

Let's go through that code step by step. The basic structure of those
@@ -124,11 +124,11 @@ is that our package set knows its final value already while we're still
defining it! This allows for the existence of the `callPackage` function:

self: let
callPackage = stdenv.lib.callPackageWith self;
callPackage = lib.callPackageWith self;
in
self // { ... Haskell package definitions here ... }

The expression `callPackage f args` translates to `stdenv.lib.callPackageWith
The expression `callPackage f args` translates to `lib.callPackageWith
self f args`. [`callPackageWith`][2] then uses reflection to determine the
names of all arguments expected by `f`. It finds those names that don't exist
in `args` in `self` and adds them to `args` to complete the function call. In
@@ -172,7 +172,7 @@ package set use the older version instead of the latest one. Furthermore, we
would like Hydra builds of `haskell.packages.lts-2_8.hslua` enabled. The
original definition from `hackage-packages.nix` disabled those builds via

hydraPlatforms = stdenv.lib.platforms.none
hydraPlatforms = lib.platforms.none

which makes sense in `haskellPackages`, because it prefers the latest version
of the package, but the older LTS set isn't happy with that choice, so it uses
@@ -247,10 +247,10 @@ but this adds a dozen highly redundant arguments to every single definition!
There might be clever ways around mentioning each of them explicitly, like:

"hslua" =
{ mkDerivation, base, bytestring, [... more inputs omitted ...]
{ mkDerivation, base, bytestring, lib, [... more inputs omitted ...]
, ...
} @ args:
stdenv.lib.callPackageWith args mkDerivation {
lib.callPackageWith args mkDerivation {
pname = "hslua";
version = "0.4.1";
[... more attributes omitted ...]
2 changes: 1 addition & 1 deletion doc/03-map-cabal-files-to-nix-without-information-loss.md
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ specifies. In case of the `conduit` example, the generated code should say:
libraryHaskellDepends = [
base exceptions lifted-base mmorph mtl resourcet transformers
transformers-base
] ++ stdenv.lib.optional (stdenv.lib.versionOlder ghc.version "7.9") void;
] ++ lib.optional (lib.versionOlder ghc.version "7.9") void;

Furthermore, Cabal flags should be mapped to boolean function arguments that
enable/disable the underlying feature and thereby modify how the Nix expression
2 changes: 1 addition & 1 deletion hackage2nix/Main.hs
Original file line number Diff line number Diff line change
@@ -175,7 +175,7 @@ main = do
withFile hackagePackagesFile WriteMode $ \h -> do
hPutStrLn h "/* hackage-packages.nix is an auto-generated file -- DO NOT EDIT! */"
hPutStrLn h ""
hPutStrLn h "{ pkgs, stdenv, callPackage }:"
hPutStrLn h "{ pkgs, lib, callPackage }:"
hPutStrLn h ""
hPutStrLn h "self: {"
hPutStrLn h ""
2 changes: 1 addition & 1 deletion src/Cabal2nix.hs
Original file line number Diff line number Diff line change
@@ -238,7 +238,7 @@ processPackage Options{..} pkg = do
-- & metaSection.platforms .~ Set.fromList optPlatform
& doCheck &&~ optDoCheck
& doBenchmark ||~ optDoBenchmark
& extraFunctionArgs %~ Set.union (Set.fromList ("inherit stdenv":map (fromString . ("inherit " ++)) optExtraArgs))
& extraFunctionArgs %~ Set.union (Set.fromList ("inherit lib":map (fromString . ("inherit " ++)) optExtraArgs))

shell :: Doc
shell = vcat
Loading