zipline: refactor environment variables (#377101)
[NixPkgs.git] / pkgs / applications / graphics / sane / config.nix
blob07cb0736690b3d4cc4a0f8512cb8b2c5db5400ca
1 { lib, stdenv }:
4   paths,
5   disabledDefaultBackends ? [ ],
6 }:
8 let
9   installSanePath = path: ''
10     if [ -e "${path}/lib/sane" ]; then
11       find "${path}/lib/sane" -maxdepth 1 -not -type d | while read backend; do
12         symlink "$backend" "$out/lib/sane/$(basename "$backend")"
13       done
14     fi
16     if [ -e "${path}/etc/sane.d" ]; then
17       find "${path}/etc/sane.d" -maxdepth 1 -not -type d | while read conf; do
18         name="$(basename $conf)"
19         if [ "$name" = "dll.conf" ] || [ "$name" = "saned.conf" ] || [ "$name" = "net.conf" ]; then
20           cat "$conf" >> "$out/etc/sane.d/$name"
21         else
22           symlink "$conf" "$out/etc/sane.d/$name"
23         fi
24       done
25     fi
27     if [ -e "${path}/etc/sane.d/dll.d" ]; then
28       find "${path}/etc/sane.d/dll.d" -maxdepth 1 -not -type d | while read conf; do
29         symlink "$conf" "$out/etc/sane.d/dll.d/$(basename $conf)"
30       done
31     fi
32   '';
33   disableBackend = backend: ''
34     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; }
35     sed -i 's/\b${backend}\b/# ${backend} disabled by nixos config/' $out/etc/sane.d/dll.conf
36   '';
38 stdenv.mkDerivation {
39   name = "sane-config";
40   dontUnpack = true;
42   installPhase =
43     ''
44       function symlink () {
45         local target=$1 linkname=$2
46         if [ -e "$linkname" ]; then
47           echo "warning: conflict for $linkname. Overriding $(readlink $linkname) with $target."
48         fi
49         ln -sfn "$target" "$linkname"
50       }
52       mkdir -p $out/etc/sane.d $out/etc/sane.d/dll.d $out/lib/sane
53     ''
54     + (lib.concatMapStrings installSanePath paths)
55     + (lib.concatMapStrings disableBackend disabledDefaultBackends);