Skip to content

Instantly share code, notes, and snippets.

@andreabedini
Last active February 9, 2023 11:06
Show Gist options
  • Save andreabedini/3e867b2d05dc98a1853513972afd8509 to your computer and use it in GitHub Desktop.
Save andreabedini/3e867b2d05dc98a1853513972afd8509 to your computer and use it in GitHub Desktop.
{
inputs.nix.url = "github:NixOS/nix/2.13.2";
outputs = { self, nixpkgs, nix }: {
packages.x86_64-linux.default =
nix.packages.x86_64-linux.nix.overrideAttrs (oldAttrs: {
separateDebugInfo = false;
phases = [ "unpackPhase" "patchPhase" "autoreconfPhase" "configurePhase" "installPhase" ];
outputs = [ "out" ];
copyIncludeFiles = ''
#!/usr/bin/env bash
while getopts ":I:" arg @CXXFLAGS@; do
case $arg in
I) # Specify p value.
echo $OPTARG
cp --no-preserve=mode -vr $OPTARG/* $out/include
;;
esac
done
'';
passAsFile = oldAttrs.passAsFile or [ ] ++ [ "copyIncludeFiles" ];
installPhase = ''
set -ex
shopt -s globstar
mkdir $out/include
./config.status --file=Makefile.config
ln -s $copyIncludeFilesPath copyIncludeFiles.sh.in
./config.status --file=copyIncludeFiles.sh
bash copyIncludeFiles.sh
cp --no-preserve=mode --parents -vr Makefile config.h **/*.mk src/**/*.{cc,cpp,hh,hpp,l,y,nix} $out
cp Makefile.config $out/Makefile.config.orig
'';
});
};
}
#
# Use like this
#
# $ cp -r --no-preserve=mode --dereference $(nix build --no-link --print-out-paths) tmp
# $ cd tmp
# $ make LDFLAGS="-larchive -lcrypto -lbrotlienc -lbrotlidec -lgc -lpthread -ldl -lcpuid"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment