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