flake.nix 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # SuperTux
  2. # Copyright (C) 2021 Ingo Ruhnke <grumbel@gmail.com>
  3. #
  4. # Permission is hereby granted, free of charge, to any person obtaining
  5. # a copy of this software and associated documentation files (the
  6. # "Software"), to deal in the Software without restriction, including
  7. # without limitation the rights to use, copy, modify, merge, publish,
  8. # distribute, sublicense, and/or sell copies of the Software, and to
  9. # permit persons to whom the Software is furnished to do so, subject to
  10. # the following conditions:
  11. #
  12. # The above copyright notice and this permission notice shall be
  13. # included in all copies or substantial portions of the Software.
  14. #
  15. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. {
  23. description = "A 2D platform game featuring Tux the penguin";
  24. inputs = {
  25. nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
  26. flake-utils.url = "github:numtide/flake-utils";
  27. tinycmmc.url = "github:grumbel/tinycmmc";
  28. tinycmmc.inputs.nixpkgs.follows = "nixpkgs";
  29. tinycmmc.inputs.flake-utils.follows = "flake-utils";
  30. sexpcpp.url = "github:lispparser/sexp-cpp";
  31. sexpcpp.inputs.nixpkgs.follows = "nixpkgs";
  32. sexpcpp.inputs.flake-utils.follows = "flake-utils";
  33. sexpcpp.inputs.tinycmmc.follows = "tinycmmc";
  34. tinygettext.url = "github:tinygettext/tinygettext";
  35. tinygettext.inputs.nixpkgs.follows = "nixpkgs";
  36. tinygettext.inputs.flake-utils.follows = "flake-utils";
  37. tinygettext.inputs.tinycmmc.follows = "tinycmmc";
  38. SDL2_ttf.url = "github:SuperTux/SDL_ttf";
  39. SDL2_ttf.inputs.nixpkgs.follows = "nixpkgs";
  40. SDL2_ttf.inputs.flake-utils.follows = "flake-utils";
  41. squirrel_src.url = "github:albertodemichelis/squirrel";
  42. squirrel_src.flake = false;
  43. };
  44. outputs = { self, nixpkgs, flake-utils,
  45. tinycmmc, sexpcpp, tinygettext, SDL2_ttf,
  46. squirrel_src }:
  47. flake-utils.lib.eachDefaultSystem (system:
  48. let
  49. pkgs = nixpkgs.legacyPackages.${system};
  50. in rec {
  51. packages = flake-utils.lib.flattenTree rec {
  52. squirrel = pkgs.stdenv.mkDerivation {
  53. pname = "squirrel";
  54. version = "3.2";
  55. src = squirrel_src;
  56. nativeBuildInputs = [
  57. pkgs.cmake
  58. ];
  59. };
  60. supertux2 = pkgs.stdenv.mkDerivation rec {
  61. pname = "supertux2";
  62. # FIXME: Should use `git describe` to get the version
  63. # number or leave it to cmake, but the .git/ directory
  64. # isn't included in the Nix store.
  65. version = "0.6.3-${nixpkgs.lib.substring 0 8 self.lastModifiedDate}-${self.shortRev or "dirty"}";
  66. src = nixpkgs.lib.cleanSource ./.;
  67. patchPhase = let
  68. ver = builtins.splitVersion version;
  69. in ''
  70. substituteInPlace config.h.cmake \
  71. --replace "#define _SQ64" ""
  72. cat > version.cmake <<EOF
  73. SET(SUPERTUX_VERSION_MAJOR ${builtins.elemAt ver 0})
  74. SET(SUPERTUX_VERSION_MINOR ${builtins.elemAt ver 1})
  75. SET(SUPERTUX_VERSION_PATCH ${builtins.elemAt ver 2})
  76. SET(SUPERTUX_VERSION_TWEAK ${builtins.elemAt ver 3})
  77. SET(SUPERTUX_VERSION_STRING "v${version}")
  78. SET(SUPERTUX_VERSION_BUILD "${builtins.elemAt ver 4}")
  79. EOF
  80. '';
  81. cmakeFlags = [
  82. "-DINSTALL_SUBDIR_BIN=bin"
  83. "-DUSE_SYSTEM_SDL2_TTF=ON"
  84. ];
  85. enableParallelBuilding = true;
  86. nativeBuildInputs = [
  87. pkgs.cmake
  88. pkgs.pkgconfig
  89. pkgs.makeWrapper
  90. pkgs.git
  91. ];
  92. postFixup = ''
  93. wrapProgram $out/bin/supertux2 \
  94. --prefix LIBGL_DRIVERS_PATH ":" "${pkgs.mesa.drivers}/lib/dri" \
  95. --prefix LD_LIBRARY_PATH ":" "${pkgs.mesa.drivers}/lib"
  96. '';
  97. buildInputs = [
  98. squirrel
  99. sexpcpp.packages.${system}.default
  100. tinygettext.packages.${system}.default
  101. SDL2_ttf.packages.${system}.default
  102. pkgs.physfs
  103. pkgs.libpng
  104. pkgs.boost
  105. pkgs.curl
  106. pkgs.fmt_8
  107. pkgs.libGL
  108. pkgs.libGLU
  109. pkgs.glew
  110. pkgs.gtest
  111. pkgs.glm
  112. pkgs.SDL2
  113. pkgs.SDL2_image
  114. pkgs.openal
  115. pkgs.libvorbis
  116. pkgs.libogg
  117. pkgs.gtest
  118. ];
  119. };
  120. default = supertux2;
  121. };
  122. }
  123. );
  124. }