Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{lib, stdenv, fetchFromGitHub, fuse, bison, flex, openssl, python3, ncurses, readline, 2 autoconf, automake, libtool, pkg-config, zlib, libaio, libxml2, acl, sqlite, 3 liburcu, liburing, attr, makeWrapper, coreutils, gnused, gnugrep, which, 4 openssh, gawk, findutils, util-linux, lvm2, btrfs-progs, e2fsprogs, xfsprogs, systemd, 5 rsync, glibc, rpcsvc-proto, libtirpc, gperftools, nixosTests 6}: 7let 8 # NOTE: On each glusterfs release, it should be checked if gluster added 9 # new, or changed, Python scripts whose PYTHONPATH has to be set in 10 # `postFixup` below, and whose runtime deps need to go into 11 # `nativeBuildInputs`. 12 # The command 13 # find /nix/store/...-glusterfs-.../ -name '*.py' -executable 14 # can help with finding new Python scripts. 15 16 buildInputs = [ 17 fuse openssl ncurses readline 18 zlib libaio libxml2 19 acl sqlite liburcu attr util-linux libtirpc gperftools 20 liburing 21 (python3.withPackages (pkgs: [ 22 pkgs.flask 23 pkgs.prettytable 24 pkgs.requests 25 pkgs.pyxattr 26 ])) 27 # NOTE: `python3` has to be *AFTER* the above `python3.withPackages`, 28 # to ensure that the packages are available but the `toPythonPath` 29 # shell function used in `postFixup` is also still available. 30 python3 31 ]; 32 # Some of the headers reference acl 33 propagatedBuildInputs = [ 34 acl 35 ]; 36 # Packages from which GlusterFS calls binaries at run-time from PATH, 37 # with comments on which commands are known to be called by it. 38 runtimePATHdeps = [ 39 attr # getfattr setfattr 40 btrfs-progs # btrfs 41 coreutils # lots of commands in bash scripts 42 e2fsprogs # tune2fs 43 findutils # find 44 gawk # awk 45 glibc # getent 46 gnugrep # grep 47 gnused # sed 48 lvm2 # lvs 49 openssh # ssh 50 rsync # rsync, e.g. for geo-replication 51 systemd # systemctl 52 util-linux # mount umount 53 which # which 54 xfsprogs # xfs_info 55 ]; 56in stdenv.mkDerivation rec { 57 pname = "glusterfs"; 58 version = "11.0"; 59 60 src = fetchFromGitHub { 61 owner = "gluster"; 62 repo = pname; 63 rev = "v${version}"; 64 sha256 = "sha256-K2w8YqpoLzkzUuoOuI7itfC81sJPUf6elOL8LCrxKAI="; 65 }; 66 inherit buildInputs propagatedBuildInputs; 67 68 patches = [ 69 # Upstream invokes `openssl version -d` to derive the canonical system path 70 # for certificates, which resolves to a nix store path, so this patch 71 # statically sets the configure.ac value. There's probably a less-brittle 72 # way to do this! (this will likely fail on a version bump) 73 # References: 74 # - https://github.com/gluster/glusterfs/issues/3234 75 # - https://github.com/gluster/glusterfs/commit/a7dc43f533ad4b8ff68bf57704fefc614da65493 76 ./ssl_cert_path.patch 77 ]; 78 79 postPatch = '' 80 sed -e '/chmod u+s/d' -i contrib/fuse-util/Makefile.am 81 substituteInPlace libglusterfs/src/glusterfs/lvm-defaults.h \ 82 --replace '/sbin/' '${lvm2}/bin/' 83 substituteInPlace libglusterfs/src/glusterfs/compat.h \ 84 --replace '/bin/umount' '${util-linux}/bin/umount' 85 substituteInPlace contrib/fuse-lib/mount-gluster-compat.h \ 86 --replace '/bin/mount' '${util-linux}/bin/mount' 87 ''; 88 89 # Note that the VERSION file is something that is present in release tarballs 90 # but not in git tags (at least not as of writing in v3.10.1). 91 # That's why we have to create it. 92 # Without this, gluster (at least 3.10.1) will fail very late and cryptically, 93 # for example when setting up geo-replication, with a message like 94 # Staging of operation 'Volume Geo-replication Create' failed on localhost : Unable to fetch master volume details. Please check the master cluster and master volume. 95 # What happens here is that the gverify.sh script tries to compare the versions, 96 # but fails when the version is empty. 97 # See upstream GlusterFS bug https://bugzilla.redhat.com/show_bug.cgi?id=1452705 98 preConfigure = '' 99 patchShebangs build-aux/pkg-version 100 echo "v${version}" > VERSION 101 ./autogen.sh 102 export PYTHON=${python3}/bin/python 103 ''; 104 105 configureFlags = [ 106 "--localstatedir=/var" 107 ]; 108 109 nativeBuildInputs = [ autoconf automake libtool pkg-config bison flex makeWrapper rpcsvc-proto ]; 110 111 makeFlags = [ "DESTDIR=$(out)" ]; 112 113 enableParallelBuilding = true; 114 115 postInstall = '' 116 cp -r $out/$out/* $out 117 rm -r $out/nix 118 ''; 119 120 postFixup = '' 121 # glusterd invokes `gluster` and other utilities when telling other glusterd nodes to run commands. 122 # For example for `peer_georep-sshkey` key generation, so `$out/bin` is needed in the PATH. 123 # It also invokes bash scripts like `gverify.sh`. 124 # It also invokes executable Python scripts in `$out/libexec/glusterfs`, which is why we set up PYTHONPATH accordingly. 125 # We set up the paths for the main entry point executables. 126 127 GLUSTER_PATH="${lib.makeBinPath runtimePATHdeps}:$out/bin" 128 GLUSTER_PYTHONPATH="$(toPythonPath $out):$out/libexec/glusterfs" 129 GLUSTER_LD_LIBRARY_PATH="$out/lib" 130 131 wrapProgram $out/bin/glusterd --set PATH "$GLUSTER_PATH" --set PYTHONPATH "$GLUSTER_PYTHONPATH" --set LD_LIBRARY_PATH "$GLUSTER_LD_LIBRARY_PATH" 132 wrapProgram $out/bin/gluster --set PATH "$GLUSTER_PATH" --set PYTHONPATH "$GLUSTER_PYTHONPATH" --set LD_LIBRARY_PATH "$GLUSTER_LD_LIBRARY_PATH" 133 wrapProgram $out/sbin/mount.glusterfs --set PATH "$GLUSTER_PATH" --set PYTHONPATH "$GLUSTER_PYTHONPATH" --set LD_LIBRARY_PATH "$GLUSTER_LD_LIBRARY_PATH" 134 135 # Set Python environment for the Python based utilities. 136 # It would be nice if there was a better way to do this, automatically for all of them. 137 # Also, this is brittle: If we forget a dependency or gluster adds a new one, things will break deep inside gluster. 138 # We should better try to get an explicit list of Python dependencies from gluster and ensure all of them are in the PYTHONPATH of all these python scripts. 139 # But at the time of writing (gluster 3.10), gluster only provides this in form of a gluster.spec file for RPM creation, 140 # and even that one is not complete (for example it doesn't mention the `flask` dependency). 141 142 wrapProgram $out/bin/gluster-eventsapi --set PATH "$GLUSTER_PATH" --set PYTHONPATH "$GLUSTER_PYTHONPATH" --set LD_LIBRARY_PATH "$GLUSTER_LD_LIBRARY_PATH" 143 wrapProgram $out/bin/gluster-georep-sshkey --set PATH "$GLUSTER_PATH" --set PYTHONPATH "$GLUSTER_PYTHONPATH" --set LD_LIBRARY_PATH "$GLUSTER_LD_LIBRARY_PATH" 144 wrapProgram $out/bin/gluster-mountbroker --set PATH "$GLUSTER_PATH" --set PYTHONPATH "$GLUSTER_PYTHONPATH" --set LD_LIBRARY_PATH "$GLUSTER_LD_LIBRARY_PATH" 145 wrapProgram $out/bin/glusterfind --set PATH "$GLUSTER_PATH" --set PYTHONPATH "$GLUSTER_PYTHONPATH" --set LD_LIBRARY_PATH "$GLUSTER_LD_LIBRARY_PATH" 146 147 # Note that we only wrap the symlinks in $out/bin, not the actual executable scripts in $out/libexec/glusterfs. 148 # This is because those scripts use `__file__` in their program logic 149 # (see https://github.com/gluster/glusterfs/blob/v3.10.1/extras/cliutils/cliutils.py#L116) 150 # which would break if we changed the file name (which is what `wrapProgram` does). 151 # Luckily, `libexec` scripts are never supposed to be invoked straight from PATH, 152 # instead they are invoked directly from `gluster` or `glusterd`, which is why it is 153 # sufficient to set PYTHONPATH for those executables. 154 # 155 # Exceptions to these rules are the `glusterfind` `brickfind.py` and `changelog.py` 156 # crawlers, which are directly invoked on other gluster nodes using a remote SSH command 157 # issues by `glusterfind`. 158 159 wrapProgram $out/share/glusterfs/scripts/eventsdash.py --set PATH "$GLUSTER_PATH" --set PYTHONPATH "$GLUSTER_PYTHONPATH" --set LD_LIBRARY_PATH "$GLUSTER_LD_LIBRARY_PATH" 160 wrapProgram $out/libexec/glusterfs/glusterfind/brickfind.py --set PATH "$GLUSTER_PATH" --set PYTHONPATH "$GLUSTER_PYTHONPATH" --set LD_LIBRARY_PATH "$GLUSTER_LD_LIBRARY_PATH" 161 wrapProgram $out/libexec/glusterfs/glusterfind/changelog.py --set PATH "$GLUSTER_PATH" --set PYTHONPATH "$GLUSTER_PYTHONPATH" --set LD_LIBRARY_PATH "$GLUSTER_LD_LIBRARY_PATH" 162 ''; 163 164 doInstallCheck = true; 165 166 # Below we run Python programs. That generates .pyc/.pyo files. 167 # By default they are indeterministic because such files contain time stamps 168 # (see https://nedbatchelder.com/blog/200804/the_structure_of_pyc_files.html). 169 # So we use the same environment variables as in 170 # https://github.com/NixOS/nixpkgs/blob/249b34aadca7038207492f29142a3456d0cecec3/pkgs/development/interpreters/python/mk-python-derivation.nix#L61 171 # to make these files deterministic. 172 # A general solution to this problem might be brought by #25707. 173 DETERMINISTIC_BUILD = 1; 174 PYTHONHASHSEED = 0; 175 176 installCheckPhase = '' 177 # Tests that the above programs work without import errors. 178 # For testing it manually in a shell you may want to substitute `$out` with `$(dirname $(readlink -f $(which gluster)))/../`. 179 $out/bin/glusterd --help 180 # $out/bin/gluster help # can't do this because even `gluster help` tries to write to `/var/log/glusterfs/cli.log` 181 $out/bin/gluster-eventsapi --help 182 $out/bin/gluster-georep-sshkey --help 183 $out/bin/gluster-mountbroker --help 184 $out/bin/glusterfind --help 185 # gfid_to_path.py doesn't accept --help, and it requires different arguments 186 # (a dir as single argument) than the usage prints when stdin is not a TTY. 187 # The `echo ""` is just so that stdin is not a TTY even if you try this line 188 # on a real TTY for testing purposes. 189 echo "" | (mkdir -p nix-test-dir-for-gfid_to_path && touch b && $out/libexec/glusterfs/gfind_missing_files/gfid_to_path.py nix-test-dir-for-gfid_to_path) 190 $out/share/glusterfs/scripts/eventsdash.py --help 191 192 # this gets falsely loaded as module by glusterfind 193 rm -r $out/bin/conf.py 194 ''; 195 196 passthru.tests = { 197 glusterfs = nixosTests.glusterfs; 198 }; 199 200 meta = with lib; { 201 description = "Distributed storage system"; 202 homepage = "https://www.gluster.org"; 203 license = licenses.lgpl3Plus; # dual licese: choice of lgpl3Plus or gpl2 204 maintainers = [ maintainers.raskin ]; 205 platforms = with platforms; linux ++ freebsd; 206 }; 207}