252 lines
6.4 KiB
Nix
252 lines
6.4 KiB
Nix
{
|
|
description = "A SQLite database containing open source japanese language translation data";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "nixpkgs/nixos-22.05";
|
|
|
|
flake-utils = {
|
|
url = "github:numtide/flake-utils";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
|
|
nix-dart = {
|
|
url = "github:tadfisher/nix-dart";
|
|
inputs = {
|
|
nixpkgs.follows = "nixpkgs";
|
|
flake-utils.follows = "flake-utils";
|
|
};
|
|
};
|
|
|
|
JMdictSrc = {
|
|
url = "http://ftp.edrdg.org/pub/Nihongo/JMdict.gz";
|
|
flake = false;
|
|
};
|
|
|
|
JMdictWithExamplesSrc = {
|
|
url = "http://ftp.edrdg.org/pub/Nihongo/JMdict_e_examp.gz";
|
|
flake = false;
|
|
};
|
|
|
|
RADKFILESrc = {
|
|
url = "http://ftp.usf.edu/pub/ftp.monash.edu.au/pub/nihongo/radkfile.gz";
|
|
flake = false;
|
|
};
|
|
|
|
KANJIDIC2Src = {
|
|
url = "http://nihongo.monash.edu/kanjidic2/kanjidic2.xml.gz";
|
|
flake = false;
|
|
};
|
|
|
|
};
|
|
|
|
outputs = {
|
|
self,
|
|
nixpkgs,
|
|
flake-utils,
|
|
nix-dart,
|
|
JMdictSrc,
|
|
JMdictWithExamplesSrc,
|
|
RADKFILESrc,
|
|
KANJIDIC2Src
|
|
}: let
|
|
system = "x86_64-linux";
|
|
pkgs = import nixpkgs {
|
|
inherit system;
|
|
overlays = [
|
|
# (final: prev: { dart = nix-dart.packages.${system}.dart; })
|
|
nix-dart.overlay
|
|
];
|
|
};
|
|
inherit (pkgs) lib;
|
|
|
|
in {
|
|
devShell.${system} = pkgs.mkShell {
|
|
buildInputs = with pkgs; [
|
|
nix-dart.packages.${system}.pub2nix-lock
|
|
dart
|
|
gnumake
|
|
sqlite
|
|
sqlite-web
|
|
sqlint
|
|
sqlfluff
|
|
];
|
|
};
|
|
|
|
defaultPackage.${system} = self.packages.${system}.database;
|
|
|
|
packages.${system} = let
|
|
inherit (pkgs.stdenv) mkDerivation;
|
|
dbName = "main.db";
|
|
|
|
edrdgMetadata = {
|
|
license = {
|
|
shortName = "EDRDG";
|
|
fullName = "Electronic Dictionary Research and Development Group General Dictionary Licence";
|
|
url = "http://www.csse.monash.edu.au/~jwb/edrdg/licence.html";
|
|
};
|
|
maintainers = [ "h7x4 <h7x4@nani.wtf>" ];
|
|
platforms = lib.platforms.all;
|
|
};
|
|
in {
|
|
JMdict = mkDerivation {
|
|
name = "JMdict";
|
|
|
|
srcs = [
|
|
JMdictSrc
|
|
JMdictWithExamplesSrc
|
|
];
|
|
dontUnpack = true;
|
|
|
|
nativeBuildInputs = with pkgs; [ xmlformat ];
|
|
buildPhase = ''
|
|
gzip -dkc ${JMdictSrc} > JMdict.xml
|
|
gzip -dkc ${JMdictWithExamplesSrc} > JMdict_with_examples.xml
|
|
'';
|
|
# xmlformat -i JMdict.xml
|
|
# xmlformat -i JMdict_with_examples.xml
|
|
|
|
installPhase = ''
|
|
mkdir $out
|
|
cp JMdict.xml $out
|
|
cp JMdict_with_examples.xml $out
|
|
'';
|
|
|
|
meta = edrdgMetadata // {
|
|
description = "A Japanese-Multilingual Dictionary providing lexical data for japanese words";
|
|
homepage = "https://www.edrdg.org/jmdict/j_jmdict.html";
|
|
};
|
|
};
|
|
|
|
RADKFILE = mkDerivation {
|
|
name = "RADKFILE";
|
|
|
|
src = RADKFILESrc;
|
|
dontUnpack = true;
|
|
|
|
buildPhase = ''
|
|
gzip -dkc $src > radkfile
|
|
iconv -f EUC-JP -t UTF-8 -o radkfile_utf8 radkfile
|
|
'';
|
|
|
|
installPhase = ''
|
|
mkdir $out
|
|
cp radkfile_utf8 $out
|
|
'';
|
|
|
|
meta = edrdgMetadata // {
|
|
description = "A file providing searchable decompositions of kanji characters";
|
|
homepage = "https://www.edrdg.org/krad/kradinf.html";
|
|
};
|
|
};
|
|
|
|
KANJIDIC2 = mkDerivation {
|
|
name = "KANJIDIC2";
|
|
|
|
src = KANJIDIC2Src;
|
|
dontUnpack = true;
|
|
|
|
nativeBuildInputs = with pkgs; [ xmlformat ];
|
|
buildPhase = ''
|
|
gzip -dkc ${KANJIDIC2Src} > kanjidic2.xml
|
|
'';
|
|
# xmlformat -i kanjidic2.xml
|
|
|
|
installPhase = ''
|
|
mkdir $out
|
|
cp kanjidic2.xml $out
|
|
'';
|
|
|
|
meta = edrdgMetadata // {
|
|
# description = "A Japanese-Multilingual Dictionary providing lexical data for japanese words";
|
|
# homepage = "https://www.edrdg.org/jmdict/j_jmdict.html";
|
|
};
|
|
};
|
|
|
|
database_generator = let
|
|
buildDartPackage = nix-dart.builders.${system}.buildDartPackage.override {
|
|
dart = nix-dart.packages.${system}.dart-dev;
|
|
};
|
|
in (buildDartPackage {
|
|
pname = "database_generator";
|
|
version = "1.0";
|
|
|
|
src = builtins.filterSource (path: type: baseNameOf path != ".dart_tool") ./.;
|
|
|
|
preBuild = ''
|
|
dart --version
|
|
'';
|
|
|
|
specFile = ./pubspec.yaml;
|
|
lockFile = ./pub2nix.lock;
|
|
}).overrideAttrs(old: {
|
|
buildInputs = [nix-dart.packages.${system}.dart-dev];
|
|
buildPhase = builtins.replaceStrings ["pub"] ["dart pub"] old.buildPhase;
|
|
});
|
|
|
|
database = mkDerivation {
|
|
name = "database";
|
|
src = builtins.filterSource (path: type: baseNameOf path != dbName) ./.;
|
|
|
|
nativeBuildInputs = with pkgs; [
|
|
sqlite
|
|
self.packages.${system}.database_generator
|
|
];
|
|
buildPhase = ''
|
|
mkdir -p data
|
|
ln -s ${self.packages.${system}.JMdict}/* data
|
|
ln -s ${self.packages.${system}.RADKFILE}/* data
|
|
ln -s ${self.packages.${system}.KANJIDIC2}/* data
|
|
|
|
sqlite3 ${dbName} < migrations/0001_initial.sql
|
|
sqlite3 ${dbName} < migrations/0002_insert_info_values.sql
|
|
|
|
ja_db ${pkgs.sqlite.out}/lib/libsqlite3.so
|
|
'';
|
|
|
|
installPhase = ''
|
|
mkdir -p $out
|
|
cp migrations/0001_initial.sql $out/schema.sql
|
|
cp ${dbName} $out/${dbName}
|
|
'';
|
|
};
|
|
|
|
docs = mkDerivation {
|
|
name = "docs";
|
|
src = self.packages.${system}.database;
|
|
nativeBuildInputs = with pkgs; [
|
|
schemaspy
|
|
sqlite-jdbc
|
|
];
|
|
|
|
buildPhase = let
|
|
properties = pkgs.writeText "sqlite.properties" ''
|
|
description=SQLite
|
|
driver=org.sqlite.JDBC
|
|
driverPath=${pkgs.sqlite-jdbc}/share/java/sqlite-jdbc-3.25.2.jar
|
|
connectionSpec=jdbc:sqlite:<db>
|
|
'';
|
|
|
|
args = pkgs.writeText "schemaspy.properties" ''
|
|
schemaspy.cat="%"
|
|
schemaspy.t=sqlite
|
|
schemaspy.sso=true
|
|
schemaspy.db=${dbName}
|
|
schemaspy.o=docs
|
|
schemaspy.s=schema.sql
|
|
'';
|
|
|
|
in ''
|
|
cp ${args} ./schemaspy.properties
|
|
ls
|
|
schemaspy -t ${properties}
|
|
'';
|
|
|
|
installPhase = ''
|
|
cp -r docs $out
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
}
|