Skip to content

Commit

Permalink
nixos/sane: allow to disable enabled-by-default plugins
Browse files Browse the repository at this point in the history
use case: disabling v4l plugin because I don't use my webcam as a
scanner.
  • Loading branch information
symphorien committed Feb 19, 2021
1 parent 6b1057b commit c64fb50
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 11 additions & 1 deletion nixos/modules/services/hardware/sane.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let
};

backends = [ pkg netConf ] ++ optional config.services.saned.enable sanedConf ++ config.hardware.sane.extraBackends;
saneConfig = pkgs.mkSaneConfig { paths = backends; };
saneConfig = pkgs.mkSaneConfig { paths = backends; inherit (config.hardware.sane) disabledDefaultBackends; };

enabled = config.hardware.sane.enable || config.services.saned.enable;

Expand Down Expand Up @@ -75,6 +75,16 @@ in
example = literalExample "[ pkgs.hplipWithPlugin ]";
};

hardware.sane.disabledDefaultBackends = mkOption {
type = types.listOf types.str;
default = [];
example = [ "v4l" ];
description = ''
Names of backends which are enabled by default but should be disabled.
See <literal>$SANE_CONFIG_DIR/dll.conf</literal> for the list of possible names.
'';
};

hardware.sane.configDir = mkOption {
type = types.str;
internal = true;
Expand Down
13 changes: 10 additions & 3 deletions pkgs/applications/graphics/sane/config.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{ lib, stdenv }:

{ paths }:
{ paths, disabledDefaultBackends ? [] }:

with lib;
let installSanePath = path: ''
let
installSanePath = path: ''
if [ -e "${path}/lib/sane" ]; then
find "${path}/lib/sane" -maxdepth 1 -not -type d | while read backend; do
symlink "$backend" "$out/lib/sane/$(basename "$backend")"
Expand All @@ -27,6 +28,10 @@ let installSanePath = path: ''
done
fi
'';
disableBackend = backend: ''
grep -q '${backend}' $out/etc/sane.d/dll.conf || { echo '${backend} is not a default plugin in $SANE_CONFIG_DIR/dll.conf'; exit 1; }
substituteInPlace $out/etc/sane.d/dll.conf --replace '${backend}' '# ${backend} disabled in nixos config'
'';
in
stdenv.mkDerivation {
name = "sane-config";
Expand All @@ -42,5 +47,7 @@ stdenv.mkDerivation {
}
mkdir -p $out/etc/sane.d $out/etc/sane.d/dll.d $out/lib/sane
'' + concatMapStrings installSanePath paths;
''
+ (concatMapStrings installSanePath paths)
+ (concatMapStrings disableBackend disabledDefaultBackends);
}

0 comments on commit c64fb50

Please sign in to comment.