sct: fix segfault when DISPLAY is empty, clean up derivation

+28 -23
+10
pkgs/tools/X11/sct/DISPLAY-segfault.patch
··· 1 + --- a/sct.c 2017-09-22 00:44:20.270421881 +0000 2 + +++ b/sct.c 2017-09-26 10:50:38.964562740 +0000 3 + @@ -36,6 +36,7 @@ 4 + main(int argc, char **argv) 5 + { 6 + Display *dpy = XOpenDisplay(NULL); 7 + + if (!dpy) exit(1); 8 + int screen = DefaultScreen(dpy); 9 + Window root = RootWindow(dpy, screen); 10 +
+18 -23
pkgs/tools/X11/sct/default.nix
··· 1 - {stdenv, fetchurl, libX11, libXrandr}: 1 + { stdenv, fetchurl, libX11, libXrandr }: 2 + 2 3 stdenv.mkDerivation rec { 3 4 name = "sct"; 4 - buildInputs = [libX11 libXrandr]; 5 + 5 6 src = fetchurl { 6 7 url = http://www.tedunangst.com/flak/files/sct.c; 7 8 sha256 = "01f3ndx3s6d2qh2xmbpmhd4962dyh8yp95l87xwrs4plqdz6knhd"; 8 - 9 - # Discussion regarding the checksum and the source code can be found in issue #17163 10 - # The code seems unmaintained, yet an unknown (probably small change) in the code caused 11 - # failed builds as the checksum had changed. 12 - # The checksum is updated for now, however, this is unpractical and potentially unsafe 13 - # so any future changes might warrant a fork of the (feature complete) project. 14 - # The code is under public domain. 15 - 16 9 }; 17 - phases = ["patchPhase" "buildPhase" "installPhase"]; 18 - patchPhase = '' 19 - sed -re "/Xlibint/d" ${src} > sct.c 20 - ''; 21 - buildPhase = "gcc -std=c99 sct.c -o sct -lX11 -lXrandr -lm"; 22 - installPhase = '' 23 - mkdir -p "$out/bin" 24 - cp sct "$out/bin" 25 - ''; 26 - meta = { 27 - description = ''A minimal utility to set display colour temperature''; 28 - maintainers = [stdenv.lib.maintainers.raskin]; 29 - platforms = with stdenv.lib.platforms; linux ++ freebsd ++ openbsd; 10 + 11 + unpackPhase = "cat ${src} > sct.c"; 12 + patches = [ ./DISPLAY-segfault.patch ]; 13 + 14 + buildInputs = [ libX11 libXrandr ]; 15 + buildPhase = "cc sct.c -o sct -lm -lX11 -lXrandr"; 16 + 17 + installPhase = "install -Dt $out/bin sct"; 18 + 19 + meta = with stdenv.lib; { 20 + homepage = https://www.tedunangst.com/flak/post/sct-set-color-temperature; 21 + description = "A minimal utility to set display colour temperature"; 22 + maintainers = [ maintainers.raskin ]; 23 + license = licenses.publicDomain; 24 + platforms = with platforms; linux ++ freebsd ++ openbsd; 30 25 }; 31 26 }