Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 89 lines 2.1 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 ruby, 6 bundlerEnv, 7 udevCheckHook, 8}: 9let 10 11 # To create Gemfile.lock and gemset.nix 12 # > nix-shell -p bundix bundler zlib 13 # > bundle install 14 # > bundix 15 gems = bundlerEnv { 16 name = "polar-env"; 17 inherit ruby; 18 gemdir = ./.; 19 }; 20 21in 22stdenv.mkDerivation rec { 23 24 pname = "polar"; 25 # The package has no releases so let's use the latest commit 26 version = "unstable-2021-01-12"; 27 28 src = fetchFromGitHub { 29 owner = "cmaion"; 30 repo = pname; 31 rev = "be15f5f897f8a919dd639009873147dca2a9cea0"; 32 sha256 = "0gqkqfrqnrsy6avg372xwqj22yz8g6r2hnzbw6197b1rf7zr1il7"; 33 }; 34 35 prePatch = '' 36 for script in polar_* 37 do 38 substituteInPlace $script --replace "#{File.dirname(__FILE__)}/lib" "$out/lib/polar" 39 done 40 ''; 41 buildInputs = [ 42 gems 43 ruby 44 ]; 45 46 nativeBuildInputs = [ 47 udevCheckHook 48 ]; 49 50 doInstallCheck = true; 51 52 # See: https://wiki.nixos.org/wiki/Packaging/Ruby 53 # 54 # Put library content under lib/polar and the raw scripts under share/polar. 55 # Then, wrap the scripts so that they use the correct ruby environment and put 56 # these wrapped executables under bin. 57 installPhase = '' 58 install -Dm644 -t $out/etc/udev/rules.d ./pkg/99-polar.rules 59 mkdir -p $out/{bin,lib/polar,share/polar} 60 cp -r lib/* $out/lib/polar/ 61 for script in ./polar_* 62 do 63 raw="$out/share/polar/$script" 64 bin="$out/bin/$script" 65 cp "$script" "$raw" 66 cat > $bin <<EOF 67 #!/bin/sh -e 68 exec ${gems}/bin/bundle exec ${ruby}/bin/ruby "$raw" "\$@" 69 EOF 70 chmod +x $bin 71 done 72 ''; 73 74 meta = with lib; { 75 description = "Command-line tools to interact with Polar watches"; 76 longDescription = '' 77 A set of command line tools written in Ruby to interact with Polar watches 78 and decode raw data files. 79 80 Udev rules can be added as: 81 82 services.udev.packages = [ pkgs.polar ] 83 ''; 84 homepage = "https://github.com/cmaion/polar"; 85 license = licenses.gpl3Only; 86 maintainers = with maintainers; [ jluttine ]; 87 platforms = platforms.linux; 88 }; 89}