From ca9212b56cd7ee70d9e9825537a481f36eb6598c Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Sat, 24 Jul 2021 23:57:59 +0200 Subject: [PATCH 1/2] dict-dbs: deprecate phases --- pkgs/servers/dict/dictd-db-collector.nix | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/pkgs/servers/dict/dictd-db-collector.nix b/pkgs/servers/dict/dictd-db-collector.nix index f635c98602d9..35429ebe2c7d 100644 --- a/pkgs/servers/dict/dictd-db-collector.nix +++ b/pkgs/servers/dict/dictd-db-collector.nix @@ -1,20 +1,20 @@ {stdenv, lib, dict}: ({dictlist, allowList ? ["127.0.0.1"], denyList ? []}: /* - dictlist is a list of form + dictlist is a list of form [ { filename = /path/to/files/basename; name = "name"; } ] - basename.dict.dz and basename.index should be + basename.dict.dz and basename.index should be dict files. Or look below for other options. allowList is a list of IP/domain *-wildcarded strings denyList is the same.. */ let - link_arguments = map + link_arguments = map (x: '' "${x.filename}" '') - dictlist; - databases = lib.concatStrings (map (x : + dictlist; + databases = lib.concatStrings (map (x : "${x.name} ${x.filename}\n") dictlist); allow = lib.concatStrings (map (x: "allow ${x}\n") allowList); deny = lib.concatStrings (map (x: "deny ${x}\n") denyList); @@ -24,18 +24,18 @@ let ${deny} } "; - installPhase = '' + installPhase = '' mkdir -p $out/share/dictd cd $out/share/dictd - echo "${databases}" >databases.names + echo "${databases}" >databases.names echo "${accessSection}" > dictd.conf - for j in ${toString link_arguments}; do + for j in ${toString link_arguments}; do name="$(egrep ' '"$j"\$ databases.names)" name=''${name% $j} if test -d "$j"; then if test -d "$j"/share/dictd ; then echo "Got store path $j" - j="$j"/share/dictd + j="$j"/share/dictd fi echo "Directory reference: $j" i=$(ls "$j""/"*.index) @@ -47,8 +47,8 @@ let locale=$(cat "$(dirname "$i")"/locale) base="$(basename "$i")" echo "Locale is $locale" - export LC_ALL=$locale - export LANG=$locale + export LC_ALL=$locale + export LANG=$locale if test -e "$i".dict.dz; then ln -s "$i".dict.dz else @@ -73,7 +73,6 @@ in stdenv.mkDerivation { name = "dictd-dbs"; - phases = ["installPhase"]; buildInputs = [dict]; inherit installPhase; From 9b6c409fb441915da659307a94655fa978ddf256 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Sun, 25 Jul 2021 00:18:13 +0200 Subject: [PATCH 2/2] dict-dbs: fmt --- pkgs/servers/dict/dictd-db-collector.nix | 133 ++++++++++++----------- 1 file changed, 68 insertions(+), 65 deletions(-) diff --git a/pkgs/servers/dict/dictd-db-collector.nix b/pkgs/servers/dict/dictd-db-collector.nix index 35429ebe2c7d..faf0fd24831c 100644 --- a/pkgs/servers/dict/dictd-db-collector.nix +++ b/pkgs/servers/dict/dictd-db-collector.nix @@ -1,79 +1,82 @@ -{stdenv, lib, dict}: -({dictlist, allowList ? ["127.0.0.1"], denyList ? []}: +{ stdenv, lib, dict }: +({ dictlist, allowList ? [ "127.0.0.1" ], denyList ? [ ] }: + /* - dictlist is a list of form - [ { filename = /path/to/files/basename; - name = "name"; } ] - basename.dict.dz and basename.index should be - dict files. Or look below for other options. - allowList is a list of IP/domain *-wildcarded strings - denyList is the same.. + dictlist is a list of form + [ { filename = /path/to/files/basename; + name = "name"; } ] + basename.dict.dz and basename.index should be + dict files. Or look below for other options. + allowList is a list of IP/domain *-wildcarded strings + denyList is the same.. */ let - link_arguments = map - (x: '' "${x.filename}" '') - dictlist; - databases = lib.concatStrings (map (x : - "${x.name} ${x.filename}\n") dictlist); - allow = lib.concatStrings (map (x: "allow ${x}\n") allowList); - deny = lib.concatStrings (map (x: "deny ${x}\n") denyList); - accessSection = " - access { - ${allow} - ${deny} - } - "; - installPhase = '' - mkdir -p $out/share/dictd - cd $out/share/dictd - echo "${databases}" >databases.names - echo "${accessSection}" > dictd.conf - for j in ${toString link_arguments}; do - name="$(egrep ' '"$j"\$ databases.names)" - name=''${name% $j} - if test -d "$j"; then - if test -d "$j"/share/dictd ; then - echo "Got store path $j" - j="$j"/share/dictd - fi - echo "Directory reference: $j" - i=$(ls "$j""/"*.index) - i="''${i%.index}"; - else - i="$j"; - fi - echo "Basename is $i" - locale=$(cat "$(dirname "$i")"/locale) - base="$(basename "$i")" - echo "Locale is $locale" - export LC_ALL=$locale - export LANG=$locale - if test -e "$i".dict.dz; then - ln -s "$i".dict.dz - else - cp "$i".dict . - dictzip "$base".dict - fi - ln -s "$i".index . - dictfmt_index2word --locale $locale < "$base".index > "$base".word || true - dictfmt_index2suffix --locale $locale < "$base".index > "$base".suffix || true + link_arguments = map + (x: '' "${x.filename}" '') + dictlist; + databases = lib.concatStrings (map + (x: + "${x.name} ${x.filename}\n") + dictlist); + allow = lib.concatStrings (map (x: "allow ${x}\n") allowList); + deny = lib.concatStrings (map (x: "deny ${x}\n") denyList); + accessSection = " + access { + ${allow} + ${deny} + } +"; + installPhase = '' + mkdir -p $out/share/dictd + cd $out/share/dictd + echo "${databases}" >databases.names + echo "${accessSection}" > dictd.conf + for j in ${toString link_arguments}; do + name="$(egrep ' '"$j"\$ databases.names)" + name=''${name% $j} + if test -d "$j"; then + if test -d "$j"/share/dictd ; then + echo "Got store path $j" + j="$j"/share/dictd + fi + echo "Directory reference: $j" + i=$(ls "$j""/"*.index) + i="''${i%.index}"; + else + i="$j"; + fi + echo "Basename is $i" + locale=$(cat "$(dirname "$i")"/locale) + base="$(basename "$i")" + echo "Locale is $locale" + export LC_ALL=$locale + export LANG=$locale + if test -e "$i".dict.dz; then + ln -s "$i".dict.dz + else + cp "$i".dict . + dictzip "$base".dict + fi + ln -s "$i".index . + dictfmt_index2word --locale $locale < "$base".index > "$base".word || true + dictfmt_index2suffix --locale $locale < "$base".index > "$base".suffix || true - echo "database $name {" >> dictd.conf - echo " data $out/share/dictd/$base.dict.dz" >> dictd.conf - echo " index $out/share/dictd/$base.index" >> dictd.conf - echo " index_word $out/share/dictd/$base.word" >> dictd.conf - echo " index_suffix $out/share/dictd/$base.suffix" >> dictd.conf - echo "}" >> dictd.conf - done - ''; + echo "database $name {" >> dictd.conf + echo " data $out/share/dictd/$base.dict.dz" >> dictd.conf + echo " index $out/share/dictd/$base.index" >> dictd.conf + echo " index_word $out/share/dictd/$base.word" >> dictd.conf + echo " index_suffix $out/share/dictd/$base.suffix" >> dictd.conf + echo "}" >> dictd.conf + done + ''; in stdenv.mkDerivation { name = "dictd-dbs"; - buildInputs = [dict]; + buildInputs = [ dict ]; inherit installPhase; })