1{
2 stdenv,
3 fetchzip,
4 jam,
5 unzip,
6 libX11,
7 libXxf86vm,
8 libXrandr,
9 libXinerama,
10 libXrender,
11 libXext,
12 libtiff,
13 libjpeg,
14 libpng,
15 libXScrnSaver,
16 writeText,
17 libXdmcp,
18 libXau,
19 lib,
20 openssl,
21 buildPackages,
22 replaceVars,
23 udevCheckHook,
24 writeScript,
25}:
26
27stdenv.mkDerivation rec {
28 pname = "argyllcms";
29 version = "3.3.0";
30
31 src = fetchzip {
32 # Kind of flacky URL, it was reaturning 406 and inconsistent binaries for a
33 # while on me. It might be good to find a mirror
34 url = "https://www.argyllcms.com/Argyll_V${version}_src.zip";
35 hash = "sha256-xpbj15GzpGS0d1UjzvYiZ1nmmTjNIyv0ST2blmi7ZSk=";
36 };
37
38 nativeBuildInputs = [
39 jam
40 udevCheckHook
41 unzip
42 ];
43
44 patches = lib.optional (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) (
45 # Build process generates files by compiling and then invoking an executable.
46 replaceVars ./jam-cross.patch {
47 emulator = stdenv.hostPlatform.emulator buildPackages;
48 }
49 );
50
51 postPatch = lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) ''
52 substituteInPlace Jambase \
53 --replace "-m64" ""
54 '';
55
56 preConfigure =
57 let
58 # The contents of this file comes from the Jamtop file from the
59 # root of the ArgyllCMS distribution, rewritten to pick up Nixpkgs
60 # library paths. When ArgyllCMS is updated, make sure that changes
61 # in that file is reflected here.
62 jamTop = writeText "argyllcms_jamtop" ''
63 DESTDIR = "/" ;
64 REFSUBDIR = "share/argyllcms" ;
65
66 # Keep this DESTDIR anchored to Jamtop. PREFIX is used literally
67 ANCHORED_PATH_VARS = DESTDIR ;
68
69 # Tell standalone libraries that they are part of Argyll:
70 DEFINES += ARGYLLCMS ;
71
72 # enable serial instruments & support
73 USE_SERIAL = true ;
74
75 # enable fast serial instruments & support
76 USE_FAST_SERIAL = true ; # (Implicit in USE_SERIAL too)
77
78 # enable USB instruments & support
79 USE_USB = true ;
80
81 # enable dummy Demo Instrument (only if code is available)
82 USE_DEMOINST = true ;
83
84 # enable Video Test Patch Generator and 3DLUT device support
85 # (V2.0.0 and above)
86 USE_VTPGLUT = false ;
87
88 # enable Printer device support
89 USE_PRINTER = false ;
90
91 # enable CMF Measurement device and accessory support (if present)
92 USE_CMFM = false ;
93
94 # Use ArgyllCMS version of libusb (deprecated - don't use)
95 USE_LIBUSB = false ;
96
97 # Compile in graph plotting code (Not fully implemented)
98 USE_PLOT = true ; # [true]
99
100 JPEGLIB = ;
101 JPEGINC = ;
102 HAVE_JPEG = true ;
103
104 TIFFLIB = ;
105 TIFFINC = ;
106 HAVE_TIFF = true ;
107
108 PNGLIB = ;
109 PNGINC = ;
110 HAVE_PNG = true ;
111
112 ZLIB = ;
113 ZINC = ;
114 HAVE_Z = true ;
115
116 SSLLIB = ;
117 SSLINC = ;
118 HAVE_SSL = true ;
119
120 LINKFLAGS +=
121 ${lib.concatStringsSep " " (map (x: "-L${x}/lib") buildInputs)}
122 -lrt -lX11 -lXext -lXxf86vm -lXinerama -lXrandr -lXau -lXdmcp -lXss
123 -ljpeg -ltiff -lpng -lssl ;
124 '';
125 in
126 ''
127 cp ${jamTop} Jamtop
128 substituteInPlace Makefile --replace "-j 3" "-j $NIX_BUILD_CORES"
129 # Remove tiff, jpg and png to be sure the nixpkgs-provided ones are used
130 rm -rf tiff jpg png
131
132 export AR="$AR rusc"
133 '';
134
135 buildInputs = [
136 libtiff
137 libjpeg
138 libpng
139 libX11
140 libXxf86vm
141 libXrandr
142 libXinerama
143 libXext
144 libXrender
145 libXScrnSaver
146 libXdmcp
147 libXau
148 openssl
149 ];
150
151 buildFlags = [ "all" ];
152
153 makeFlags = [
154 "PREFIX=${placeholder "out"}"
155 ];
156
157 # Install udev rules, but remove lines that set up the udev-acl
158 # stuff, since that is handled by udev's own rules (70-udev-acl.rules)
159 postInstall = ''
160 rm -v $out/bin/License.txt
161 mkdir -p $out/etc/udev/rules.d
162 sed -i '/udev-acl/d' usb/55-Argyll.rules
163 cp -v usb/55-Argyll.rules $out/etc/udev/rules.d/
164
165 sed -i -e 's/^CREATED .*/CREATED "'"$(date -d @$SOURCE_DATE_EPOCH)"'"/g' $out/share/argyllcms/RefMediumGamut.gam
166
167 '';
168
169 doInstallCheck = true;
170
171 passthru = {
172 updateScript = writeScript "update-argyllcms" ''
173 #!/usr/bin/env nix-shell
174 #!nix-shell -i bash -p curl pcre common-updater-scripts
175
176 set -eu -o pipefail
177
178 # Expect the text in format of 'Current Version 3.0.1 (19th October 2023)'
179 new_version="$(curl -s https://www.argyllcms.com/ |
180 pcregrep -o1 '>Current Version ([0-9.]+) ')"
181 update-source-version ${pname} "$new_version"
182 '';
183 };
184
185 meta = with lib; {
186 homepage = "https://www.argyllcms.com/";
187 description = "Color management system (compatible with ICC)";
188 license = licenses.gpl3;
189 maintainers = [ ];
190 platforms = platforms.linux;
191 };
192}