2 lib, stdenv, fetchFromGitHub,
5 libxcrypt, zlib, openssl,
6 gmp, gperftools, readline,
7 libedit, libarchive, Security,
9 # optional dependencies
30 libX11, libXpm, libXext, libXft, libXinerama, libjpeg, libXt, libSM, freetype, fontconfig,
32 # gcc/g++ as runtime dependency
33 withNativeCompiler ? true
35 # Packs must be installed from a local directory during the build, with dependencies
36 # resolved manually, e.g. to install the 'julian' pack, which depends on the 'delay', 'list_util' and 'typedef' packs:
37 # julian = pkgs.fetchzip {
38 # name = "swipl-pack-julian";
39 # url = "https://github.com/mndrix/julian/archive/v0.1.3.zip";
40 # sha256 = "1sgql7c21p3c5m14kwa0bcmlwn9fql612krn9h36gla1j9yjdfgy";
42 # delay = pkgs.fetchzip {
43 # name = "swipl-pack-delay";
44 # url = "https://github.com/mndrix/delay/archive/v0.3.3.zip";
45 # sha256 = "0ira87afxnc2dnbbmgwmrr8qvary8lhzvhqwd52dccm6yqd3nybg";
47 # list_util = pkgs.fetchzip {
48 # name = "swipl-pack-list_util";
49 # url = "https://github.com/mndrix/list_util/archive/v0.13.0.zip";
50 # sha256 = "0lx7vffflak0y8l8vg8k0g8qddwwn23ksbz02hi3f8rbarh1n89q";
52 # typedef = builtins.fetchTarball {
53 # name = "swipl-pack-typedef";
54 # url = "https://raw.githubusercontent.com/samer--/prolog/master/typedef/release/typedef-0.1.9.tgz";
55 # sha256 = "056nqjn01g18fb1b2qivv9s7hb4azk24nx2d4kvkbmm1k91f44p3";
57 # swi-prolog = pkgs.swi-prolog.override { extraPacks = map (dep-path: "'file://${dep-path}'") [
58 # julian delay list_util typedef
61 , extraLibraries ? [] # removed option - see below
65 # minorVersion is even for stable, odd for unstable
68 # This package provides several with* options, which replaces the old extraLibraries option.
69 # This error should help users that still use this option find their way to these flags.
70 # We can probably remove this after one NixOS version.
71 extraLibraries' = if extraLibraries == [] then [] else throw
72 "option 'extraLibraries' removed - use 'with*' options (e.g., 'withJava'), or overrideAttrs to inject extra build dependencies";
74 packInstall = swiplPath: pack: ''
75 ${swiplPath}/bin/swipl -g "pack_install(${pack}, [package_directory(\"${swiplPath}/lib/swipl/extra-pack\"), silent(true), interactive(false), git(false)])." -t "halt."
77 withGui' = withGui && !stdenv.hostPlatform.isDarwin;
78 optionalDependencies = []
79 ++ (lib.optional withDb db)
80 ++ (lib.optional withJava jdk)
81 ++ (lib.optional withOdbc unixODBC)
82 ++ (lib.optional withPcre pcre2)
83 ++ (lib.optional withPython python3)
84 ++ (lib.optional withYaml libyaml)
85 ++ (lib.optionals withGui' [ libXt libXext libXpm libXft libXinerama
86 libjpeg libSM freetype fontconfig
88 ++ (lib.optional stdenv.hostPlatform.isDarwin Security)
95 # SWI-Prolog has two repositories: swipl and swipl-devel.
96 # - `swipl`, which tracks stable releases and backports
97 # - `swipl-devel` which tracks continuous development
98 src = fetchFromGitHub {
102 hash = "sha256-O9ogltcbBST111FA85jEVW6jGOLJSt/5PeBABtMu2Ws=";
103 fetchSubmodules = true;
106 # Add the packInstall path to the swipl pack search path
108 echo "user:file_search_path(pack, '$out/lib/swipl/extra-pack')." >> boot/init.pl
111 nativeBuildInputs = [ cmake ninja ];
122 ] ++ optionalDependencies;
124 hardeningDisable = [ "format" ];
126 cmakeFlags = [ "-DSWIPL_INSTALL_IN_LIB=ON" ]
127 ++ lib.optionals (!withNativeCompiler) [
128 # without these options, the build will embed full compiler paths
129 "-DSWIPL_CC=${if stdenv.hostPlatform.isDarwin then "clang" else "gcc"}"
130 "-DSWIPL_CXX=${if stdenv.hostPlatform.isDarwin then "clang++" else "g++"}"
134 mkdir -p $out/lib/swipl/extra-pack
137 postInstall = builtins.concatStringsSep "\n"
138 ( builtins.map (packInstall "$out") extraPacks
142 homepage = "https://www.swi-prolog.org";
143 description = "Prolog compiler and interpreter";
144 license = lib.licenses.bsd2;
145 mainProgram = "swipl";
146 platforms = lib.platforms.linux ++ lib.optionals (!withGui) lib.platforms.darwin;
147 maintainers = [ lib.maintainers.meditans lib.maintainers.matko ];