# build with `nix-build IceSL.nix`

{ pkgs ? import
    (builtins.fetchGit {
      name = "nixos-22.11-2023_01_01";
      url = "https://github.com/nixos/nixpkgs-unstable/";
      ref = "refs/heads/nixos-22.11";
      rev = "913a47cd064cc06440ea84e5e0452039a85781f0";
    })
    { }
}:

with pkgs;

stdenv.mkDerivation rec {
  name = "IceSL-${version}";

  version = "2.5.3-beta5";

  src = fetchurl {
    url = "https://icesl.loria.fr/assets/other/download.php?build=${version}&version=stable&os=amd64";
    hash = "sha256-kR6pJodgIw1N6mfhoA58N3mlkCuKPkxQ2nvs2BGgIj0=";
    #hash = "sha256-yz8M6beyHnIaXn8Op9uJV+3Q8sLCVEArEA40VKKo7ic="
  };

  buildInputs = [
   #(pkgs.buildFHSUserEnv {
    unzip
    autoPatchelfHook
    glfw
    libGLU
    openssl_1_1
    #openssl_3_0
    #glew
    #glew110
    glew-egl
    glfw
    
  ];

  phases = [
    "unpackPhase"
    "installPhase"
    "fixupPhase"
  ];


  unpackPhase = ''
    unzip $src
  '';

  installPhase = ''
    mkdir -p $out/
    cp -r icesl/* $out/
  '';
}
