pytrainer: unpin python 3.10
[NixPkgs.git] / pkgs / applications / graphics / sane / config.nix
blobc637ff3cfcd3201a152f22b82b713dfc74517add
1 { lib, stdenv }:
3 { paths, disabledDefaultBackends ? [] }:
6 let
7 installSanePath = path: ''
8       if [ -e "${path}/lib/sane" ]; then
9         find "${path}/lib/sane" -maxdepth 1 -not -type d | while read backend; do
10           symlink "$backend" "$out/lib/sane/$(basename "$backend")"
11         done
12       fi
14       if [ -e "${path}/etc/sane.d" ]; then
15         find "${path}/etc/sane.d" -maxdepth 1 -not -type d | while read conf; do
16           name="$(basename $conf)"
17           if [ "$name" = "dll.conf" ] || [ "$name" = "saned.conf" ] || [ "$name" = "net.conf" ]; then
18             cat "$conf" >> "$out/etc/sane.d/$name"
19           else
20             symlink "$conf" "$out/etc/sane.d/$name"
21           fi
22         done
23       fi
25       if [ -e "${path}/etc/sane.d/dll.d" ]; then
26         find "${path}/etc/sane.d/dll.d" -maxdepth 1 -not -type d | while read conf; do
27           symlink "$conf" "$out/etc/sane.d/dll.d/$(basename $conf)"
28         done
29       fi
30     '';
31     disableBackend = backend: ''
32       grep -w -q '${backend}' $out/etc/sane.d/dll.conf || { echo '${backend} is not a default plugin in $SANE_CONFIG_DIR/dll.conf'; exit 1; }
33       sed -i 's/\b${backend}\b/# ${backend} disabled by nixos config/' $out/etc/sane.d/dll.conf
34     '';
36 stdenv.mkDerivation {
37   name = "sane-config";
38   dontUnpack = true;
40   installPhase = ''
41     function symlink () {
42       local target=$1 linkname=$2
43       if [ -e "$linkname" ]; then
44         echo "warning: conflict for $linkname. Overriding $(readlink $linkname) with $target."
45       fi
46       ln -sfn "$target" "$linkname"
47     }
49     mkdir -p $out/etc/sane.d $out/etc/sane.d/dll.d $out/lib/sane
50   ''
51   + (lib.concatMapStrings installSanePath paths)
52   + (lib.concatMapStrings disableBackend disabledDefaultBackends);