Skip to content

Commit

Permalink
Add a matrix of stdenvs to the flake
Browse files Browse the repository at this point in the history
For a (currently hardcoded and limited) list of stdenvs,
make `.#$nix-${stdenvName}` correspond to a Nix built with the
corresponding stdenv.

For example, `.#nix-${clang11Stdenv}` is Nix built with clang11.

Likewise, `devShell.x86_64-linux.clang11StdenvPackages` is a development
shell for Nix with clang11

Fix #4129

/cc @Pamplemousse
  • Loading branch information
thufschmitt committed Jul 13, 2021
1 parent 099df07 commit d700ebd
Showing 1 changed file with 49 additions and 23 deletions.
72 changes: 49 additions & 23 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,31 @@

crossSystems = [ "armv6l-linux" "armv7l-linux" ];

stdenvs = [ "gccStdenv" "clangStdenv" "clang11Stdenv" "stdenv" ];

forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
forAllSystemsAndStdenvs = f: forAllSystems (system:
let stdenvsPackages =
nixpkgs.lib.listToAttrs
(map
(n:
nixpkgs.lib.nameValuePair "${n}Packages" (
f system n
)) stdenvs
);
in
stdenvsPackages // stdenvsPackages.stdenvPackages
);

forAllStdenvs = stdenvs: f: nixpkgs.lib.genAttrs stdenvs (stdenv: f stdenv);

# Memoize nixpkgs for different platforms for efficiency.
nixpkgsFor = forAllSystems (system:
nixpkgsFor = forAllSystemsAndStdenvs (system: stdenv:
import nixpkgs {
inherit system;
overlays = [ self.overlay ];
overlays = [
(overlayFor (p: p.${stdenv}))
];
}
);

Expand Down Expand Up @@ -254,18 +272,15 @@
$(cat ${installerClosureInfo}/store-paths)
'';

in {

# A Nixpkgs overlay that overrides the 'nix' and
# 'nix.perl-bindings' packages.
overlay = final: prev: {

overlayFor = getStdenv: final: prev:
let currentStdenv = getStdenv final; in
{
# An older version of Nix to test against when using the daemon.
# Currently using `nixUnstable` as the stable one doesn't respect
# `NIX_DAEMON_SOCKET_PATH` which is needed for the tests.
nixStable = prev.nix;

nix = with final; with commonDeps pkgs; stdenv.mkDerivation {
nix = with final; with commonDeps pkgs; currentStdenv.mkDerivation {
name = "nix-${version}";
inherit version;

Expand All @@ -287,9 +302,9 @@
mkdir -p $out/lib
cp -pd ${boost}/lib/{libboost_context*,libboost_thread*,libboost_system*} $out/lib
rm -f $out/lib/*.a
${lib.optionalString stdenv.isLinux ''
${lib.optionalString currentStdenv.isLinux ''
chmod u+w $out/lib/*.so.*
patchelf --set-rpath $out/lib:${stdenv.cc.cc.lib}/lib $out/lib/libboost_thread.so.*
patchelf --set-rpath $out/lib:${currentStdenv.cc.cc.lib}/lib $out/lib/libboost_thread.so.*
''}
'';

Expand All @@ -316,7 +331,7 @@

strictDeps = true;

passthru.perl-bindings = with final; stdenv.mkDerivation {
passthru.perl-bindings = with final; currentStdenv.mkDerivation {
name = "nix-perl-${version}";

src = self;
Expand All @@ -336,8 +351,8 @@
boost
nlohmann_json
]
++ lib.optional (stdenv.isLinux || stdenv.isDarwin) libsodium
++ lib.optional stdenv.isDarwin darwin.apple_sdk.frameworks.Security;
++ lib.optional (currentStdenv.isLinux || currentStdenv.isDarwin) libsodium
++ lib.optional currentStdenv.isDarwin darwin.apple_sdk.frameworks.Security;

configureFlags = ''
--with-dbi=${perlPackages.DBI}/${pkgs.perl.libPrefix}
Expand All @@ -351,13 +366,14 @@

};

lowdown = with final; stdenv.mkDerivation rec {

lowdown = with final; currentStdenv.mkDerivation rec {
name = "lowdown-0.8.4";

/*
src = fetchurl {
url = "https://kristaps.bsd.lv/lowdown/snapshots/${name}.tar.gz";
hash = "sha512-U9WeGoInT9vrawwa57t6u9dEdRge4/P+0wLxmQyOL9nhzOEUU2FRz2Be9H0dCjYE7p2v3vCXIYk40M+jjULATw==";
url = "https://kristaps.bsd.lv/lowdown/snapshots/${name}.tar.gz";
hash = "sha512-U9WeGoInT9vrawwa57t6u9dEdRge4/P+0wLxmQyOL9nhzOEUU2FRz2Be9H0dCjYE7p2v3vCXIYk40M+jjULATw==";
};
*/

Expand All @@ -368,15 +384,20 @@
nativeBuildInputs = [ buildPackages.which ];

configurePhase = ''
${if (stdenv.isDarwin && stdenv.isAarch64) then "echo \"HAVE_SANDBOX_INIT=false\" > configure.local" else ""}
${if (currentStdenv.isDarwin && currentStdenv.isAarch64) then "echo \"HAVE_SANDBOX_INIT=false\" > configure.local" else ""}
./configure \
PREFIX=${placeholder "dev"} \
BINDIR=${placeholder "bin"}/bin
'';
'';
};

};

in {

# A Nixpkgs overlay that overrides the 'nix' and
# 'nix.perl-bindings' packages.
overlay = overlayFor (p: p.stdenv);

hydraJobs = {

# Binary package for various platforms.
Expand Down Expand Up @@ -591,15 +612,20 @@
doInstallCheck = true;
installCheckFlags = "sysconfdir=$(out)/etc";
};
}) crossSystems)));
}) crossSystems)) // (builtins.listToAttrs (map (stdenvName:
nixpkgsFor.${system}.lib.nameValuePair
"nix-${stdenvName}"
nixpkgsFor.${system}."${stdenvName}Packages".nix
) stdenvs))
);

defaultPackage = forAllSystems (system: self.packages.${system}.nix);

devShell = forAllSystems (system:
devShell = forAllSystemsAndStdenvs (system: stdenv:
with nixpkgsFor.${system};
with commonDeps pkgs;

stdenv.mkDerivation {
nixpkgsFor.${system}.${stdenv}.mkDerivation {
name = "nix";

outputs = [ "out" "dev" "doc" ];
Expand Down

0 comments on commit d700ebd

Please sign in to comment.