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

Update to nixos-23.05 #116

Merged
merged 29 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
27ae28d
Bump nixpkgs.nix to pin to nixos-21.11 commit 573095944e7.
cdepillabout Dec 15, 2021
49fce8d
Bump nixpkgs submodule to be on 21.11.
cdepillabout Dec 15, 2021
b92d824
Make sure the nixpkgs submodule is looking at NixOS/nixpkgs.
cdepillabout Dec 15, 2021
dbe55ac
Get the basic example working with 21.11.
cdepillabout Dec 15, 2021
9c4227e
Add more ghc to cabal version mappings.
cdepillabout Dec 15, 2021
2b08698
Bump to ghc-8.10.7. Nixpkgs is on LTS-18.16.
cdepillabout Dec 15, 2021
b3f4744
postgresl's tests fail when building with musl, so disable postgrest …
cdepillabout Dec 15, 2021
f30e2f5
Apparently there is a curlMinimal top-level derivation now, which als…
cdepillabout Dec 15, 2021
6e3e1df
brotli support was added to curl and it needs to be explicitly disabl…
cdepillabout Dec 15, 2021
4b1f174
Make sure static archives symlinks are created for openblas.
cdepillabout Dec 17, 2021
4fa209c
Make sure blas-ffi uses openblasCompat.
cdepillabout Dec 17, 2021
83b1822
Disable stackage executable magico because of gfortran linking error.
cdepillabout Dec 17, 2021
d41b96a
Disable stackage packages that depend on postgres.
cdepillabout Dec 17, 2021
1b57af7
Make sure libdevil has libdeflate as buildInput.
cdepillabout Dec 17, 2021
3d0be9a
Drop to postgresql-11 and re-enable all Haskell packages that use pos…
cdepillabout Dec 18, 2021
14d4ace
new ncurses
robx Jul 27, 2022
6bdf17b
Update to nixos-23.05
nh2 Jun 10, 2023
b11ecc6
Fix `approachPkgs` being the wrong value.
nh2 Jun 10, 2023
9dfc7f2
Add comment on curl brotli disabling
nh2 Jun 10, 2023
d90f0ec
Disable GHC dwarf support
nh2 Jun 10, 2023
c91a9b4
Add `useArchiveFilesForTemplateHaskell` option.
nh2 Jun 11, 2023
0236a82
Fix `workingStackageExecutables`'s YAML loading.
nh2 Jun 12, 2023
2c20f14
Add nixpkgs patch to add .a files to bzip2 and zstd
nh2 Jun 13, 2023
70aa4a1
Make `.working` pass
nh2 Jun 13, 2023
9dd4c43
Remove old compilers:
nh2 Jun 13, 2023
da073d5
Remove workarounds no longer necessary with nixos-23.05
nh2 Jun 13, 2023
5793932
Fix arbtt needing libxcb
nh2 Jun 13, 2023
63232fc
Fix more packages. `workingStackageExecutables` builds on top of nixo…
nh2 Jul 13, 2023
ce1f737
Implement suggestion for bazel / rules_haskell
nh2 Jul 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "nixpkgs"]
path = nixpkgs
url = https://github.com/nh2/nixpkgs.git
url = https://github.com/NixOS/nixpkgs.git
7 changes: 3 additions & 4 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Note: This is just a minimal example. For proper usage, see the README.

{ nixpkgs ? (import ./nixpkgs.nix).pkgsMusl, compiler ? "ghc864", strip ? true }:
{ nixpkgs ? (import ./nixpkgs.nix).pkgsMusl, compiler ? "ghc8107", strip ? true }:


let
Expand All @@ -12,7 +12,7 @@ let
pname = "example-scotty-app";
version = "0.1.0.0";
src = pkgs.lib.sourceByRegex ./. [
".*\.cabal$"
".*\\.cabal$"
"^Setup.hs$"
"^Main.hs$"
];
Expand All @@ -21,7 +21,7 @@ let
enableSharedExecutables = false;
enableSharedLibraries = false;
executableHaskellDepends = [ base scotty ];
license = stdenv.lib.licenses.bsd3;
license = pkgs.lib.licenses.bsd3;
configureFlags = [
"--ghc-option=-optl=-static"
"--extra-lib-dirs=${pkgs.gmp6.override { withStatic = true; }}/lib"
Expand All @@ -37,7 +37,6 @@ let
haskellPackages = with pkgs.haskell.lib; normalHaskellPackages.override {
overrides = self: super: {
# Dependencies we need to patch
hpc-coveralls = appendPatch super.hpc-coveralls (builtins.fetchurl https://github.com/guillaume-nargeot/hpc-coveralls/pull/73/commits/344217f513b7adfb9037f73026f5d928be98d07f.patch);
};
};

Expand Down
2 changes: 1 addition & 1 deletion nixpkgs
Submodule nixpkgs updated 33271 files
3 changes: 2 additions & 1 deletion nixpkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ if builtins.getEnv "STATIC_HASKELL_NIX_CI_NIXPKGS_UNSTABLE_BUILD" == "1"
if builtins.pathExists ./nixpkgs/pkgs
then import ./nixpkgs {}
# Pinned nixpkgs version; should be kept up-to-date with our submodule.
else import (fetchTarball https://github.com/NixOS/nixpkgs/archive/d00b5a5fa6fe8bdf7005abb06c46ae0245aec8b5.tar.gz) {}
# This is nixos-21.11 as of 2021-12-15.
else import (fetchTarball https://github.com/NixOS/nixpkgs/archive/573095944e7c1d58d30fc679c81af63668b54056.tar.gz) {}
90 changes: 85 additions & 5 deletions survey/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ in
])."${approach}",

# When changing this, also change the default version of Cabal declared below
compiler ? "ghc8104",
compiler ? "ghc927",

# Tries to use `.a` files when evaluating TH, instead of `.so` files.
useArchiveFilesForTemplateHaskell ? false,

# See:
# * https://www.snoyman.com/base/
# * https://www.haskell.org/cabal/download.html
# section "Older Releases"
# * https://gitlab.haskell.org/ghc/ghc/-/wikis/commentary/libraries/version-history
defaultCabalPackageVersionComingWithGhc ?
({
ghc822 = "Cabal_2_2_0_1"; # TODO this is technically incorrect for ghc 8.2.2, should be 2.0.1.0, but nixpkgs doesn't have that
Expand All @@ -38,7 +42,10 @@ in
ghc881 = "Cabal_3_0_0_0";
ghc8104 = "Cabal_3_2_1_0";
ghc8105 = "Cabal_3_2_1_0";
ghc8107 = "Cabal_3_2_1_0";
ghc901 = "Cabal_3_4_0_0";
ghc927 = "Cabal_3_6_3_0";
ghc962 = "Cabal_3_10_1_0";
}."${compiler}"),

# Use `integer-simple` instead of `integer-gmp` to avoid linking in
Expand Down Expand Up @@ -75,6 +82,8 @@ let

lib = pkgs.lib;

approachPkgs = pkgs;

# Function that tells us if a given entry in a `haskellPackages` package set
# is a proper Haskell package (as opposed to some fancy function like
# `.override` and the likes).
Expand Down Expand Up @@ -505,6 +514,7 @@ let
# `archiveFilesOverlay` below where `statify_curl_including_exe` is used.
gssSupport = false;
zlib = zlib_both;
brotliSupport = false; # When brotli is enabled, the `curl` package currently fails to link in `CCLD curl` with error `ld: ../lib/.libs/libcurl.so: undefined reference to `_kBrotliPrefixCodeRanges'`
})).overrideAttrs (old: {
dontDisableStatic = true;

Expand Down Expand Up @@ -653,7 +663,12 @@ let
#patchelf = issue_61682_throw "patchelf" previous.patchelf;
#xz = issue_61682_throw "xz" previous.xz;

postgresql = (previous.postgresql.overrideAttrs (old: { dontDisableStatic = true; })).override {
# The test-suite for PostgreSQL 13 fails:
# https://github.com/NixOS/nixpkgs/issues/150930
#
# Even if you disable the test-suite, there are various linking issues.
# PostgreSQL 12 has similar issues, so we drop to PostgreSQL 11.
postgresql = (previous.postgresql_11.overrideAttrs (old: { dontDisableStatic = true; })).override {
# We need libpq, which does not need systemd,
# and systemd doesn't currently build with musl.
enableSystemd = false;
Expand Down Expand Up @@ -731,7 +746,17 @@ let
libjpeg = previous.libjpeg.override (old: { enableStatic = true; });
libjpeg_turbo = previous.libjpeg_turbo.override (old: { enableStatic = true; });

openblas = previous.openblas.override { enableStatic = true; };
openblas = (previous.openblas.override { enableStatic = true; }).overrideAttrs (old: {
# openblas doesn't create symlinks for static archives like libblas.a and
# liblapack.a. The following lines fixes this.
# https://github.com/NixOS/nixpkgs/pull/151049
postInstall = old.postInstall + ''
ln -s $out/lib/libopenblas.a $out/lib/libblas.a
ln -s $out/lib/libopenblas.a $out/lib/libcblas.a
ln -s $out/lib/libopenblas.a $out/lib/liblapack.a
ln -s $out/lib/libopenblas.a $out/lib/liblapacke.a
'';
});

openssl = previous.openssl.override { static = true; };

Expand Down Expand Up @@ -763,6 +788,9 @@ let
# so that `curl` can use it.
curl = statify_curl_including_exe previous.curl final.zlib_both;

# curlMinimal also needs to be statified.
curlMinimal = statify_curl_including_exe previous.curlMinimal final.zlib_both;

# `fetchurl` uses our overridden `curl` above, but `fetchurl` overrides
# `zlib` in `curl`, see
# https://github.com/NixOS/nixpkgs/blob/4a5c0e029ddbe89aa4eb4da7949219fe4e3f8472/pkgs/top-level/all-packages.nix#L296-L299
Expand Down Expand Up @@ -832,6 +860,21 @@ let
};
};

# I'm not sure why this is needed. As far as I can tell, libdevil doesn't
# directly link to libdeflate. But libdevil does link to libtiff, which
# uses libdeflate.
#
# However, if libdevil doesn't have libdeflate as a buildInput, building
# libdevil fails with linking errors.
#
# I wasn't able to report this upstream, because in nixpkgs libdevil and
# pkgsMusl.libdevil build correctly. Some transitive dependencies for
# pkgsStatic.libdevil fail to build, so it is hard to say whether this is a
# static-haskell-nix problem, or just a static-linking problem.
libdevil = previous.libdevil.overrideAttrs (oldAttrs: {
buildInputs = oldAttrs.buildInputs ++ [ final.libdeflate ];
});

};


Expand Down Expand Up @@ -1186,6 +1229,13 @@ let
# Tests fail with: doctests: <command line>: Dynamic loading not supported
headroom = dontCheck super.headroom;

# We need to explicitly get blas from openblasCompat, since
# otherwise openblas is used and Haskell programs like `resistor-cube`
# won't be able to find libblas.
blas-ffi = super.blas-ffi.override {
blas = final.openblasCompat;
};

hmatrix =
# musl does not have `random_r()`.
(enableCabalFlag super.hmatrix "no-random_r")
Expand Down Expand Up @@ -1497,10 +1547,39 @@ let

pkgsWithHaskellLibsReadyForStaticLinking = pkgsWithArchiveFiles.extend haskellLibsReadyForStaticLinkingOverlay;

fixGhc = ghcPackage0: lib.pipe ghcPackage0 [
# musl does not support libdw's alleged need for `dlopen()`, see:
# https://github.com/nh2/static-haskell-nix/pull/116#issuecomment-1585786484
#
# Nixpkgs has the `enableDwarf` argument only for GHCs versions that are built
# with Hadrian (`common-hadrian.nix`), which in nixpkgs is the case for GHC >= 9.6.
# So set `enableDwarf = true`, but not for older versions known to not use Hadrian.
(ghcPackage:
if lib.any (prefix: lib.strings.hasPrefix prefix compiler) ["ghc8" "ghc90" "ghc92" "ghc94"]
then ghcPackage # GHC < 9.6, no Hadrian
else ghcPackage.override { enableDwarf = false; }
)
(ghcPackage:
ghcPackage.override { enableRelocatedStaticLibs = useArchiveFilesForTemplateHaskell; }
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the rules_haskell use-case this requires

Suggested change
(ghcPackage:
ghcPackage.override { enableRelocatedStaticLibs = useArchiveFilesForTemplateHaskell; }
)
(ghcPackage:
ghcPackage.override {
enableRelocatedStaticLibs = useArchiveFilesForTemplateHaskell;
enableShared = !useArchiveFilesForTemplateHaskell;
}
)

That is because we require a static runtime to load static Haskell libraries for template Haskell.
Otherwise the build fails with errors like these (tested here):

/nix/store/fhr7av2b52a8dz8lii59bvydgx0vw5ap-binutils-2.39/bin/ld: cannot find -lHScolour-2.3.6-ghc9.0.2: No such file or directory
collect2: error: ld returned 1 exit status
`cc_wrapper-python' failed in phase `Linker'. (Exit code: 1)

];

# Overlay all Haskell executables are statically linked.
staticHaskellBinariesOverlay = final: previous: {
haskellPackages = previous.haskellPackages.override (old: {

# To override GHC, we need to override both `ghc` and the one in
# `buildHaskellPackages` because otherwise this code in `geneic-builder.nix`
# will make our package depend on 2 different GHCs:
# nativeGhc = buildHaskellPackages.ghc;
# depsBuildBuild = [ nativeGhc ] ...
# nativeBuildInputs = [ ghc removeReferencesTo ] ...
#
ghc = fixGhc old.ghc;
buildHaskellPackages = old.buildHaskellPackages.override (oldBuildHaskellPackages: {
ghc = fixGhc oldBuildHaskellPackages.ghc;
});

overrides = final.lib.composeExtensions (old.overrides or (_: _: {})) (self: super:
let
# We have to use `useFixedCabal` here, and cannot just rely on the
Expand All @@ -1519,7 +1598,7 @@ let
[
"--enable-executable-static" # requires `useFixedCabal`
# `enableShared` seems to be required to avoid `recompile with -fPIC` errors on some packages.
"--extra-lib-dirs=${final.ncurses.override { enableStatic = true; enableShared = true; }}/lib"
"--extra-lib-dirs=${final.ncurses.override { enableStatic = true; }}/lib"
]
# TODO Figure out why this and the below libffi are necessary.
# `working` and `workingStackageExecutables` don't seem to need that,
Expand Down Expand Up @@ -1624,14 +1703,15 @@ in
"LambdaHack" # fails `systemd` dependency erroring on `#include <printf.h>`
"language-puppet" # `base >=4.6 && <4.14, ghc-prim >=0.3 && <0.6` for dependency `protolude`
"learn-physics" # needs opengl: `cannot find -lGLU` `-lGL`
"magico" # undefined reference to `_gfortran_concat_string'
"odbc" # `odbcss.h: No such file or directory`
"qchas" # `_gfortran_concat_string` linker error via openblas
"rhine-gloss" # needs opengl: `cannot find -lGLU` `-lGL`
"soxlib" # fails `systemd` dependency erroring on `#include <printf.h>`
];

inherit normalPkgs;
approachPkgs = pkgs;
inherit approachPkgs;
# Export as `pkgs` our final overridden nixpkgs.
pkgs = pkgsWithStaticHaskellBinaries;

Expand Down