nixos/sane: allow to disable enabled-by-default plugins

use case: disabling v4l plugin because I don't use my webcam as a
scanner.

+21 -4
+11 -1
nixos/modules/services/hardware/sane.nix
··· 32 }; 33 34 backends = [ pkg netConf ] ++ optional config.services.saned.enable sanedConf ++ config.hardware.sane.extraBackends; 35 - saneConfig = pkgs.mkSaneConfig { paths = backends; }; 36 37 enabled = config.hardware.sane.enable || config.services.saned.enable; 38 ··· 73 </para></note> 74 ''; 75 example = literalExample "[ pkgs.hplipWithPlugin ]"; 76 }; 77 78 hardware.sane.configDir = mkOption {
··· 32 }; 33 34 backends = [ pkg netConf ] ++ optional config.services.saned.enable sanedConf ++ config.hardware.sane.extraBackends; 35 + saneConfig = pkgs.mkSaneConfig { paths = backends; inherit (config.hardware.sane) disabledDefaultBackends; }; 36 37 enabled = config.hardware.sane.enable || config.services.saned.enable; 38 ··· 73 </para></note> 74 ''; 75 example = literalExample "[ pkgs.hplipWithPlugin ]"; 76 + }; 77 + 78 + hardware.sane.disabledDefaultBackends = mkOption { 79 + type = types.listOf types.str; 80 + default = []; 81 + example = [ "v4l" ]; 82 + description = '' 83 + Names of backends which are enabled by default but should be disabled. 84 + See <literal>$SANE_CONFIG_DIR/dll.conf</literal> for the list of possible names. 85 + ''; 86 }; 87 88 hardware.sane.configDir = mkOption {
+10 -3
pkgs/applications/graphics/sane/config.nix
··· 1 { lib, stdenv }: 2 3 - { paths }: 4 5 with lib; 6 - let installSanePath = path: '' 7 if [ -e "${path}/lib/sane" ]; then 8 find "${path}/lib/sane" -maxdepth 1 -not -type d | while read backend; do 9 symlink "$backend" "$out/lib/sane/$(basename "$backend")" ··· 27 done 28 fi 29 ''; 30 in 31 stdenv.mkDerivation { 32 name = "sane-config"; ··· 42 } 43 44 mkdir -p $out/etc/sane.d $out/etc/sane.d/dll.d $out/lib/sane 45 - '' + concatMapStrings installSanePath paths; 46 }
··· 1 { lib, stdenv }: 2 3 + { paths, disabledDefaultBackends ? [] }: 4 5 with lib; 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")" ··· 28 done 29 fi 30 ''; 31 + disableBackend = backend: '' 32 + grep -q '${backend}' $out/etc/sane.d/dll.conf || { echo '${backend} is not a default plugin in $SANE_CONFIG_DIR/dll.conf'; exit 1; } 33 + substituteInPlace $out/etc/sane.d/dll.conf --replace '${backend}' '# ${backend} disabled in nixos config' 34 + ''; 35 in 36 stdenv.mkDerivation { 37 name = "sane-config"; ··· 47 } 48 49 mkdir -p $out/etc/sane.d $out/etc/sane.d/dll.d $out/lib/sane 50 + '' 51 + + (concatMapStrings installSanePath paths) 52 + + (concatMapStrings disableBackend disabledDefaultBackends); 53 }