Skip to content

Commit

Permalink
Use pkgs.lib instead of stdenv.lib (input-output-hk#1031)
Browse files Browse the repository at this point in the history
Fixes:

Warning: `stdenv.lib` is deprecated and will be removed in the next release. Please use `pkgs.lib` instead. For more information see NixOS/nixpkgs#108938
  • Loading branch information
hamishmack authored Feb 10, 2021
1 parent 1498e70 commit 89f50a9
Show file tree
Hide file tree
Showing 62 changed files with 270 additions and 233 deletions.
4 changes: 2 additions & 2 deletions build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ in rec {
# are not pure).
maintainer-scripts = pkgs.dontRecurseIntoAttrs {
update-hackage = import ./scripts/update-hackage.nix {
inherit (pkgs) stdenv writeScript coreutils glibc git
inherit (pkgs) stdenv lib writeScript coreutils glibc git
openssh nix-prefetch-git gawk bash curl findutils;
# Update scripts use the internal nix-tools and cabal-install (compiled with a fixed GHC version)
nix-tools = haskell.internal-nix-tools;
cabal-install = haskell.internal-cabal-install;
inherit (haskell) update-index-state-hashes;
};
update-stackage = haskell.callPackage ./scripts/update-stackage.nix {
inherit (pkgs) stdenv writeScript coreutils glibc git
inherit (pkgs) stdenv lib writeScript coreutils glibc git
openssh nix-prefetch-git gawk bash curl findutils;
# Update scripts use the internal nix-tools and cabal-install (compiled with a fixed GHC version)
nix-tools = haskell.internal-nix-tools;
Expand Down
2 changes: 1 addition & 1 deletion builder/comp-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ let
homepage = package.homepage or "";
description = package.synopsis or "";
license = haskellLib.cabalToNixpkgsLicense package.license;
platforms = if platforms == null then stdenv.lib.platforms.all else platforms;
platforms = if platforms == null then lib.platforms.all else platforms;
};

propagatedBuildInputs =
Expand Down
2 changes: 1 addition & 1 deletion builder/setup-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ let
homepage = package.homepage or "";
description = package.synopsis or "";
license = haskellLib.cabalToNixpkgsLicense package.license;
platforms = if component.platforms == null then stdenv.lib.platforms.all else component.platforms;
platforms = if component.platforms == null then lib.platforms.all else component.platforms;
};

phases = ["unpackPhase" "patchPhase" "buildPhase" "installPhase"];
Expand Down
4 changes: 2 additions & 2 deletions compiler/bootstrap/cabal-install.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ fetchurl, hackage, stdenv, ghc, zlib, src, version }:
{ fetchurl, hackage, stdenv, lib, ghc, zlib, src, version }:
let dependencies =
[ { name = "deepseq"; version = "1.4.3.0"; }
{ name = "binary"; version = "0.8.5.1"; }
Expand Down Expand Up @@ -42,7 +42,7 @@ in stdenv.mkDerivation ({
};

meta = {
platforms = stdenv.lib.platforms.all;
platforms = lib.platforms.all;
};

nativeBuildInputs = [ ghc zlib ];
Expand Down
38 changes: 19 additions & 19 deletions compiler/ghc/configured-src.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, fetchurl
{ stdenv, lib, fetchurl
, ghc-version, ghc-version-date, ghc-patches, src-spec
, targetPrefix
, targetPlatform, hostPlatform
Expand All @@ -25,18 +25,18 @@ stdenv.mkDerivation (rec {
nativeBuildInputs = [
perl autoconf automake m4 python3 sphinx
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
] ++ stdenv.lib.optional (patches != []) autoreconfHook;
] ++ lib.optional (patches != []) autoreconfHook;

# For building runtime libs
depsBuildTarget = toolsForTarget;

buildInputs = [ perl bash ] ++ (libDeps hostPlatform);

propagatedBuildInputs = [ targetPackages.stdenv.cc ]
++ stdenv.lib.optional useLLVM llvmPackages.llvm;
++ lib.optional useLLVM llvmPackages.llvm;

depsTargetTarget = map stdenv.lib.getDev (libDeps targetPlatform);
depsTargetTargetPropagated = map (stdenv.lib.getOutput "out") (libDeps targetPlatform);
depsTargetTarget = map lib.getDev (libDeps targetPlatform);
depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform);

postPatch = "patchShebangs .";

Expand All @@ -54,7 +54,7 @@ stdenv.mkDerivation (rec {
export CC="${targetCC}/bin/${targetCC.targetPrefix}cc"
export CXX="${targetCC}/bin/${targetCC.targetPrefix}cxx"
# Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${stdenv.lib.optionalString targetPlatform.isAarch32 ".gold"}"
export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString targetPlatform.isAarch32 ".gold"}"
export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as"
export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar"
export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"
Expand All @@ -64,13 +64,13 @@ stdenv.mkDerivation (rec {
echo -n "${buildMK}" > mk/build.mk
sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
'' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
'' + lib.optionalString (!stdenv.isDarwin) ''
export NIX_LDFLAGS+=" -rpath $out/lib/${targetPrefix}ghc-${version}"
'' + stdenv.lib.optionalString stdenv.isDarwin ''
'' + lib.optionalString stdenv.isDarwin ''
export NIX_LDFLAGS+=" -no_dtrace_dof"
'' + stdenv.lib.optionalString targetPlatform.useAndroidPrebuilt ''
'' + lib.optionalString targetPlatform.useAndroidPrebuilt ''
sed -i -e '5i ,("armv7a-unknown-linux-androideabi", ("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", "cortex-a8", ""))' llvm-targets
'' + stdenv.lib.optionalString targetPlatform.isMusl ''
'' + lib.optionalString targetPlatform.isMusl ''
echo "patching llvm-targets for musl targets..."
echo "Cloning these existing '*-linux-gnu*' targets:"
grep linux-gnu llvm-targets | sed 's/^/ /'
Expand All @@ -86,10 +86,10 @@ stdenv.mkDerivation (rec {
--replace '*-android*|*-gnueabi*)' \
'*-android*|*-gnueabi*|*-musleabi*)'
done
'' + stdenv.lib.optionalString (src-spec.version != ghc-version) ''
'' + lib.optionalString (src-spec.version != ghc-version) ''
substituteInPlace configure --replace 'RELEASE=YES' 'RELEASE=NO'
echo '${ghc-version}' > VERSION
'' + stdenv.lib.optionalString (ghc-version-date != null) ''
'' + lib.optionalString (ghc-version-date != null) ''
substituteInPlace configure --replace 'RELEASE=YES' 'RELEASE=NO'
echo '${ghc-version-date}' > VERSION_DATE
'';
Expand All @@ -99,24 +99,24 @@ stdenv.mkDerivation (rec {
configureFlags = [
"--datadir=$doc/share/doc/ghc"
"--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
] ++ stdenv.lib.optionals (targetLibffi != null) ["--with-system-libffi" "--with-ffi-includes=${targetLibffi.dev}/include" "--with-ffi-libraries=${targetLibffi.out}/lib"
] ++ stdenv.lib.optional (!enableIntegerSimple) [
] ++ lib.optionals (targetLibffi != null) ["--with-system-libffi" "--with-ffi-includes=${targetLibffi.dev}/include" "--with-ffi-libraries=${targetLibffi.out}/lib"
] ++ lib.optional (!enableIntegerSimple) [
"--with-gmp-includes=${targetGmp.dev}/include" "--with-gmp-libraries=${targetGmp.out}/lib"
] ++ stdenv.lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
] ++ lib.optional (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
"--with-iconv-includes=${libiconv}/include" "--with-iconv-libraries=${libiconv}/lib"
] ++ stdenv.lib.optionals (targetPlatform != hostPlatform) [
] ++ lib.optionals (targetPlatform != hostPlatform) [
"--enable-bootstrap-with-devel-snapshot"
] ++ stdenv.lib.optionals (disableLargeAddressSpace) [
] ++ lib.optionals (disableLargeAddressSpace) [
"--disable-large-address-space"
] ++ stdenv.lib.optionals (targetPlatform.isAarch32) [
] ++ lib.optionals (targetPlatform.isAarch32) [
"CFLAGS=-fuse-ld=gold"
"CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
"CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
] ;

outputs = [ "out" ];
phases = [ "unpackPhase" "patchPhase" ]
++ stdenv.lib.optional (ghc-patches != []) "autoreconfPhase"
++ lib.optional (ghc-patches != []) "autoreconfPhase"
++ [ "configurePhase" "installPhase" ];
installPhase = "cp -r . $out";
})
56 changes: 28 additions & 28 deletions compiler/ghc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# haskell.nix ships its own version of the ghc expression as it needs more
# control over the expression to isolate it against varying <nixpkgs> and
# allow us to customize it to the way haskell.nix works.
{ stdenv, haskell-nix, targetPackages
{ stdenv, lib, haskell-nix, targetPackages

# build-tools
, bootPkgs
Expand All @@ -26,7 +26,7 @@

, # If enabled, GHC will be built with the GPL-free but slower integer-simple
# library instead of the faster but GPLed integer-gmp library.
enableIntegerSimple ? !(stdenv.lib.any (stdenv.lib.meta.platformMatch stdenv.hostPlatform) gmp.meta.platforms), gmp
enableIntegerSimple ? !(lib.any (lib.meta.platformMatch stdenv.hostPlatform) gmp.meta.platforms), gmp

, # If enabled, use -fPIC when compiling static libs.
enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform && !stdenv.targetPlatform.isAarch32
Expand All @@ -42,7 +42,7 @@

, # What flavour to build. An empty string indicates no
# specific flavour and falls back to ghc default values.
ghcFlavour ? stdenv.lib.optionalString haskell-nix.haskellLib.isCrossTarget (
ghcFlavour ? lib.optionalString haskell-nix.haskellLib.isCrossTarget (
if useLLVM
then "perf-cross"
else "perf-cross-ncg"
Expand Down Expand Up @@ -82,7 +82,7 @@ let
targetGmp = targetPackages.gmp or gmp;

# TODO(@Ericson2314) Make unconditional
targetPrefix = stdenv.lib.optionalString
targetPrefix = lib.optionalString
(targetPlatform != hostPlatform)
"${targetPlatform.config}-";

Expand All @@ -93,52 +93,52 @@ let
endif
DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
INTEGER_LIBRARY = ${if enableIntegerSimple then "integer-simple" else "integer-gmp"}
'' + stdenv.lib.optionalString (targetPlatform != hostPlatform) ''
'' + lib.optionalString (targetPlatform != hostPlatform) ''
CrossCompilePrefix = ${targetPrefix}
'' + stdenv.lib.optionalString isCrossTarget ''
'' + lib.optionalString isCrossTarget ''
Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"}
HADDOCK_DOCS = NO
BUILD_SPHINX_HTML = NO
BUILD_SPHINX_PDF = NO
'' + stdenv.lib.optionalString enableRelocatedStaticLibs ''
'' + lib.optionalString enableRelocatedStaticLibs ''
GhcLibHcOpts += -fPIC
GhcRtsHcOpts += -fPIC
'' + stdenv.lib.optionalString targetPlatform.useAndroidPrebuilt ''
'' + lib.optionalString targetPlatform.useAndroidPrebuilt ''
EXTRA_CC_OPTS += -std=gnu99
'' + stdenv.lib.optionalString (!enableTerminfo) ''
'' + lib.optionalString (!enableTerminfo) ''
WITH_TERMINFO=NO
''
# musl doesn't have a system-linker. Only on x86, and on x86 we need it, as
# our elf linker for x86_64 is broken.
+ stdenv.lib.optionalString (targetPlatform.isMusl && !targetPlatform.isx86) ''
+ lib.optionalString (targetPlatform.isMusl && !targetPlatform.isx86) ''
compiler_CONFIGURE_OPTS += --flags=-dynamic-system-linker
''
# While split sections are now enabled by default in ghc 8.8 for windows,
# the seem to lead to `too many sections` errors when building base for
# profiling.
+ stdenv.lib.optionalString targetPlatform.isWindows ''
+ lib.optionalString targetPlatform.isWindows ''
SplitSections = NO
'' + stdenv.lib.optionalString (!enableLibraryProfiling) ''
'' + lib.optionalString (!enableLibraryProfiling) ''
BUILD_PROF_LIBS = NO
'';

# Splicer will pull out correct variations
libDeps = platform: stdenv.lib.optional enableTerminfo [ ncurses ]
libDeps = platform: lib.optional enableTerminfo [ ncurses ]
++ [targetLibffi]
++ stdenv.lib.optional (!enableIntegerSimple) gmp
++ stdenv.lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv
++ stdenv.lib.optional (platform.isLinux && !platform.isAarch32) numactl;
++ lib.optional (!enableIntegerSimple) gmp
++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv
++ lib.optional (platform.isLinux && !platform.isAarch32) numactl;

toolsForTarget =
if hostPlatform == buildPlatform then
[ targetPackages.stdenv.cc ] ++ stdenv.lib.optional useLLVM llvmPackages.llvm
[ targetPackages.stdenv.cc ] ++ lib.optional useLLVM llvmPackages.llvm
else assert targetPlatform == hostPlatform; # build != host == target
[ stdenv.cc ] ++ stdenv.lib.optional useLLVM buildLlvmPackages.llvm;
[ stdenv.cc ] ++ lib.optional useLLVM buildLlvmPackages.llvm;

targetCC = builtins.head toolsForTarget;

configured-src = import ./configured-src.nix {
inherit stdenv fetchurl
inherit stdenv lib fetchurl
ghc-version ghc-version-date ghc-patches src-spec
targetPrefix
targetPlatform hostPlatform
Expand Down Expand Up @@ -212,22 +212,22 @@ stdenv.mkDerivation (rec {
nativeBuildInputs = [
perl autoconf automake m4 python3 sphinx
ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
] ++ stdenv.lib.optional (patches != []) autoreconfHook;
] ++ lib.optional (patches != []) autoreconfHook;

# For building runtime libs
depsBuildTarget = toolsForTarget;

buildInputs = [ perl bash ] ++ (libDeps hostPlatform);

propagatedBuildInputs = [ targetPackages.stdenv.cc ]
++ stdenv.lib.optional useLLVM llvmPackages.llvm;
++ lib.optional useLLVM llvmPackages.llvm;

depsTargetTarget = map stdenv.lib.getDev (libDeps targetPlatform);
depsTargetTargetPropagated = map (stdenv.lib.getOutput "out") (libDeps targetPlatform);
depsTargetTarget = map lib.getDev (libDeps targetPlatform);
depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform);

# required, because otherwise all symbols from HSffi.o are stripped, and
# that in turn causes GHCi to abort
stripDebugFlags = [ "-S" ] ++ stdenv.lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols";
stripDebugFlags = [ "-S" ] ++ lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols";

# See #63511 - the only unstripped file is the debug rts which isn't meant to
# be stripped.
Expand All @@ -236,8 +236,8 @@ stdenv.mkDerivation (rec {
checkTarget = "test";

hardeningDisable = [ "format" ]
++ stdenv.lib.optional stdenv.targetPlatform.isAarch32 "pic"
++ stdenv.lib.optional stdenv.targetPlatform.isMusl "pie";
++ lib.optional stdenv.targetPlatform.isAarch32 "pic"
++ lib.optional stdenv.targetPlatform.isMusl "pie";

postInstall = ''
# Install the bash completion file.
Expand All @@ -250,7 +250,7 @@ stdenv.mkDerivation (rec {
# The ghcprog fixup is for musl (where runhaskell script just needs to point to the correct
# ghc program to work).
sed -i \
-e '2i export PATH="$PATH:${stdenv.lib.makeBinPath [ targetPackages.stdenv.cc.bintools coreutils ]}"' \
-e '2i export PATH="$PATH:${lib.makeBinPath [ targetPackages.stdenv.cc.bintools coreutils ]}"' \
-e 's/ghcprog="ghc-/ghcprog="${targetPrefix}ghc-/' \
$i
done
Expand Down Expand Up @@ -324,7 +324,7 @@ stdenv.mkDerivation (rec {
inherit (ghc.meta) license platforms;
};

} // stdenv.lib.optionalAttrs targetPlatform.useAndroidPrebuilt {
} // lib.optionalAttrs targetPlatform.useAndroidPrebuilt {
dontStrip = true;
dontPatchELF = true;
noAuditTmpdir = true;
Expand Down
10 changes: 0 additions & 10 deletions compiler/old-ghc-nix/default.nix

This file was deleted.

7 changes: 0 additions & 7 deletions compiler/old-ghc-nix/old-ghc-nix.json

This file was deleted.

2 changes: 1 addition & 1 deletion docs/tutorials/cross-compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ executables you must add package overrides to:
```nix
{
packages.bench.components.exes.bench.configureFlags =
stdenv.lib.optionals stdenv.hostPlatform.isMusl [
lib.optionals stdenv.hostPlatform.isMusl [
"--disable-executable-dynamic"
"--disable-shared"
"--ghc-option=-optl=-pthread"
Expand Down
14 changes: 14 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
},
"nixpkgs-unstable": {
"branch": "nixpkgs-unstable",
"builtin": false,
"description": "Nix Packages collection",
"homepage": "",
"owner": "NixOS",
Expand All @@ -128,5 +129,18 @@
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/410bbd828cdc6156aecd5bc91772ad3a6b1099c7.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"old-ghc-nix": {
"branch": "master",
"builtin": false,
"description": "Old and New GHC",
"homepage": null,
"owner": "angerman",
"repo": "old-ghc-nix",
"rev": "131ce9ae27d7b7afdd1d3ce8c3a74483e60b91bb",
"sha256": "0n62qr7hrqmy6h80736ji47ln759sk845g43f9cprpmcs9m4wl9i",
"type": "tarball",
"url": "https://github.com/angerman/old-ghc-nix/archive/131ce9ae27d7b7afdd1d3ce8c3a74483e60b91bb.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
Loading

0 comments on commit 89f50a9

Please sign in to comment.