jadb/flake.nix

258 lines
6.5 KiB
Nix
Raw Normal View History

2022-06-20 20:06:07 +02:00
{
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;
};
2022-08-18 21:39:36 +02:00
KANJIDIC2Src = {
url = "http://nihongo.monash.edu/kanjidic2/kanjidic2.xml.gz";
flake = false;
};
2022-06-20 20:06:07 +02:00
};
outputs = {
self,
nixpkgs,
flake-utils,
nix-dart,
JMdictSrc,
JMdictWithExamplesSrc,
2022-08-18 21:39:36 +02:00
RADKFILESrc,
KANJIDIC2Src
2022-06-20 20:06:07 +02:00
}: 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
2022-08-23 18:13:58 +02:00
xmlformat -i JMdict.xml
xmlformat -i JMdict_with_examples.xml
2022-06-20 20:06:07 +02:00
'';
installPhase = ''
mkdir $out
cp JMdict.xml $out
cp JMdict_with_examples.xml $out
2022-06-20 20:06:07 +02:00
'';
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
2022-06-20 20:06:07 +02:00
'';
installPhase = ''
mkdir $out
cp radkfile_utf8 $out
2022-06-20 20:06:07 +02:00
'';
meta = edrdgMetadata // {
description = "A file providing searchable decompositions of kanji characters";
homepage = "https://www.edrdg.org/krad/kradinf.html";
};
};
2022-08-18 21:39:36 +02:00
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;
};
2022-08-18 21:39:36 +02:00
in (buildDartPackage {
2022-06-20 20:06:07 +02:00
pname = "database_generator";
version = "1.0";
src = builtins.filterSource (path: type: baseNameOf path != ".dart_tool") ./.;
preBuild = ''
dart --version
'';
2022-06-20 20:06:07 +02:00
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) ./.;
2022-06-20 20:06:07 +02:00
nativeBuildInputs = with pkgs; [
sqlite
self.packages.${system}.database_generator
2022-06-20 20:06:07 +02:00
];
buildPhase = ''
mkdir -p data
ln -s ${self.packages.${system}.JMdict}/* data
ln -s ${self.packages.${system}.RADKFILE}/* data
2022-08-18 21:39:36 +02:00
ln -s ${self.packages.${system}.KANJIDIC2}/* data
2022-08-18 22:31:17 +02:00
for migration in migrations/*.sql; do
sqlite3 ${dbName} < $migration
done
ja_db ${pkgs.sqlite.out}/lib/libsqlite3.so
2022-06-20 20:06:07 +02:00
'';
installPhase = ''
mkdir -p $out
cp ${dbName} $out/${dbName}
'';
};
docs = mkDerivation {
name = "docs";
src = self.packages.${system}.database;
nativeBuildInputs = with pkgs; [
2022-08-23 18:13:58 +02:00
sqlite
2022-06-20 20:06:07 +02:00
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 ''
2022-08-23 18:13:58 +02:00
sqlite3 main.db ".schema" > schema.sql
2022-06-20 20:06:07 +02:00
cp ${args} ./schemaspy.properties
ls
schemaspy -t ${properties}
'';
installPhase = ''
cp -r docs $out
'';
};
};
2022-08-23 18:13:58 +02:00
hydraJobs = {
inherit (self.packages.${system}) database docs;
};
2022-06-20 20:06:07 +02:00
};
}