init commit
This commit is contained in:
208
flake.nix
Normal file
208
flake.nix
Normal file
@@ -0,0 +1,208 @@
|
||||
{
|
||||
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;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
flake-utils,
|
||||
nix-dart,
|
||||
JMdictSrc,
|
||||
JMdictWithExamplesSrc,
|
||||
RADKFILESrc
|
||||
}: 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
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
iconv -f EUC-JP -t UTF-8 -o $out radkfile
|
||||
'';
|
||||
|
||||
meta = edrdgMetadata // {
|
||||
description = "A file providing searchable decompositions of kanji characters";
|
||||
homepage = "https://www.edrdg.org/krad/kradinf.html";
|
||||
};
|
||||
};
|
||||
|
||||
database_generator = (nix-dart.builders.${system}.buildDartPackage {
|
||||
pname = "database_generator";
|
||||
version = "1.0";
|
||||
|
||||
buildInputs = [ nix-dart.packages.${system}.dart-dev ];
|
||||
|
||||
src = builtins.filterSource (path: type: baseNameOf path != ".dart_tool") ./.;
|
||||
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
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
mkdir -p data
|
||||
ln -s ${self.packages.${system}.JMdict}/* data
|
||||
ln -s ${self.packages.${system}.RADKFILE} data
|
||||
sqlite3 ${dbName} < migrations/0001_initial.sql
|
||||
sqlite3 ${dbName} < migrations/0002_insert_info_values.sql
|
||||
'';
|
||||
|
||||
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
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user