Skip to content

Instantly share code, notes, and snippets.

@DeltaEvo
Last active December 22, 2018 16:20
Show Gist options
  • Save DeltaEvo/9dbfedaa23f77b2afb8150dc97fdda3d to your computer and use it in GitHub Desktop.
Save DeltaEvo/9dbfedaa23f77b2afb8150dc97fdda3d to your computer and use it in GitHub Desktop.
minilibx nixos

Add nixos package

  • copy minilibx.nix to ~/.config/nixpkgs/minilibx.nix
curl https://gist.githubusercontent.com/DeltaEvo/9dbfedaa23f77b2afb8150dc97fdda3d/raw/06b948a696ee5b717dc27231d0adf48d29d7cf71/minilibx.nix > ~/.config/nixpkgs/minilibx.nix
  • download minilibx patch
curl https://gist.githubusercontent.com/DeltaEvo/9dbfedaa23f77b2afb8150dc97fdda3d/raw/06b948a696ee5b717dc27231d0adf48d29d7cf71/disable_xshm.patch > ~/.config/nixpkgs/disable_xshm.patch
  • add it into your packageOverrides (~/.config/nixpkgs/config.nix)
  packageOverrides = pkgs: rec {
    minilibx = pkgs.callPackage ./minilibx.nix {};
  };

Compile your project

  • launch a nix-shell with minilibx and it's dependencies
nix-shell -p gnumake minilibx xorg.libX11 xorg.libXext
  • link your binary with -lmlx -lX11 -lXext
  • enjoy 😄
diff --git a/mlx_init.c b/mlx_init.c
index 7a8db8f..66cdf1b 100644
--- a/mlx_init.c
+++ b/mlx_init.c
@@ -49,24 +49,8 @@ void *mlx_init()
int mlx_int_deal_shm(t_xvar *xvar)
{
- int use_pshm;
- int bidon;
- char *dpy;
- char buff[33];
-
- xvar->use_xshm = XShmQueryVersion(xvar->display,&bidon,&bidon,&(use_pshm));
- if (xvar->use_xshm && use_pshm)
- xvar->pshm_format = XShmPixmapFormat(xvar->display);
- else
- xvar->pshm_format = -1;
- gethostname(buff,32);
- dpy = getenv(ENV_DISPLAY);
- if (dpy && strlen(dpy) && *dpy!=':' && strncmp(dpy,buff,strlen(buff)) &&
- strncmp(dpy,LOCALHOST,strlen(LOCALHOST)) )
- {
- xvar->pshm_format = -1;
- xvar->use_xshm = 0;
- }
+ xvar->pshm_format = -1;
+ xvar->use_xshm = 0;
}
/*
{ stdenv, fetchurl, pkgconfig, libX11, libXext }:
stdenv.mkDerivation rec {
name = "minilibx-${version}";
version = "0.42";
src = fetchurl {
url = "https://projects.intra.42.fr/uploads/document/document/7/sources.tgz";
sha256 = "1lwa9n1jrp2r157bls8vq5xblqs2dx2nhj0yly7p2jzz7mwk3njw";
};
nativeBuildInputs = [ pkgconfig libX11 libXext ];
patches = [ ./disable_xshm.patch ];
configurePhase = ''
echo "INC=. \''${shell pkg-config --cflags x11 xext}" > Makefile
cat Makefile.mk | grep -v %%%% >> Makefile
cat Makefile
'';
installPhase = ''
mkdir -p $out/include
mkdir -p $out/lib
install -m 644 libmlx.a $out/lib
install -m 644 mlx.h $out/include
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment