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

Add Nix CI #86

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,12 @@ jobs:
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
make test -j$(nproc)
build-with-nix:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: cachix/install-nix-action@v13
with:
nix_path: nixpkgs=channel:nixos-stable
- name: Build the CI package set
run: nix-build default.nix -A ciPackages
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ options.inc
core
ld
gentoo
result # nix build output symlink
result-*
67 changes: 67 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
let
# Pin some fairly new nixpkgs
sources = builtins.fetchTarball {
name = "nixpkgs-unstable-2021-07-06";
url = "https://github.com/nixos/nixpkgs/archive/291b3ff5af268eb7a656bb11c73f2fe535ea2170.tar.gz";
sha256 = "1z2l7q4cmiaqb99cd8yfisdr1n6xbwcczr9020ss47y2z1cn1x7x";
};

# For bootstrapping, and also as comparison baseline
pkgs = import sources {
overlays = [
(pkgs: super: {
# TODO replace with proper packaging once https://github.com/NixOS/nixpkgs/pull/128889 is merged
mold = pkgs.stdenv.mkDerivation {
name = "mold";
src = ./.;
buildInputs = with pkgs; [ zlib openssl ];
nativeBuildInputs = with pkgs; [ autoPatchelfHook cmake xxHash ];
dontUseCmakeConfigure = true;
buildPhase = "make -j $NIX_BUILD_CORES";
installPhase = "make PREFIX=$out install";
};

binutils_mold = pkgs.wrapBintoolsWith {
bintools = pkgs.binutils-unwrapped.overrideAttrs (old: {
postInstall = "ln -sf ${pkgs.mold}/bin/mold $out/bin/ld";
});
};

stdenv_mold = super.overrideCC super.stdenv (super.wrapCCWith rec {
cc = super.gcc-unwrapped;
bintools = pkgs.binutils_mold;
});
})
];
};

# Actual nixpkgs with patched linker in all packages. Note:
# - This will bootstrap the entire toolchain and build all transitive dependencies every time mold changes.
# - Packages that require a custom linker (like lld or some special GCC) won't be built with mold regardless.
pkgsMold = import sources {
overlays = [
(self: super: {
stdenv = pkgs.stdenv_mold;
mold = pkgs.mold;
})
];
};

# Like pkgsMold, but we disable mold individually for known failing packages until their issues are resolved
pkgsMoldCI = pkgsMold.appendOverlays [
(self: super: {
inherit (pkgs)
valgrind # https://github.com/rui314/mold/issues/81#issuecomment-876425070
;
})
];
in {
inherit pkgs pkgsMold pkgsMoldCI;

# Packages we already know that work in order to catch regressions
ciPackages = with pkgsMoldCI; linkFarmFromDrvs "packages-with-mold" [
binutils
stdenv
# TODO
];
}