diff --git a/flake.nix b/flake.nix index 309cf63..906d785 100644 --- a/flake.nix +++ b/flake.nix @@ -14,7 +14,7 @@ }; packages = rec { - libgovarnam = pkgs.callPackage ./govarnam/libgovarnam.nix { }; + libgovarnam = pkgs.callPackage ./govarnam/libgovarnam.nix { selected_schemes = [ "ml" ]; }; varnam-cli = pkgs.callPackage ./govarnam { inherit libgovarnam; }; fcitx5-varnam = pkgs.callPackage ./varnam-fcitx5 { inherit libgovarnam; }; }; diff --git a/govarnam/default.nix b/govarnam/default.nix index 60497fd..f51231d 100644 --- a/govarnam/default.nix +++ b/govarnam/default.nix @@ -1,21 +1,14 @@ { lib , buildGoModule -, fetchFromGitHub , pkg-config , libgovarnam }: buildGoModule rec { pname = "varnam-cli"; - version = "1.9.1"; + version = libgovarnam.version; - src = fetchFromGitHub { - owner = "varnamproject"; - repo = "govarnam"; - rev = "v${version}"; - hash = "sha256-7SYdeOMgc8VBx0rsu6tWGND9mq0Td1VeGmZrpfsWsVE="; - fetchSubmodules = true; - }; + src = libgovarnam.src; vendorHash = "sha256-a7m2THvdi17muJI6p6OVX9cBMcmocYwju29beG2H8CY="; diff --git a/govarnam/libgovarnam.nix b/govarnam/libgovarnam.nix index 8bea219..60a957f 100644 --- a/govarnam/libgovarnam.nix +++ b/govarnam/libgovarnam.nix @@ -1,8 +1,30 @@ { lib +, fetchzip , buildGoModule , fetchFromGitHub +, selected_schemes ? [ ] }: +let + schemeShas = import ./schemes.nix; + knownSchemes = builtins.attrNames schemeShas; + selectedSchemes = + if (selected_schemes == [ ]) + then knownSchemes + else + let + unknown = lib.subtractLists knownSchemes selected_schemes; + in + if (unknown != [ ]) + then throw "Unknown scheme(s): ${lib.concatStringsSep " " unknown}" + else selected_schemes; + schemeSrcs = lib.lists.forEach selectedSchemes ( + name: (fetchzip { + url = schemeShas.${name}.url; + sha256 = schemeShas.${name}.sha; + }) + ); +in buildGoModule rec { pname = "libgovarnam"; version = "1.9.1"; @@ -47,6 +69,10 @@ buildGoModule rec { mkdir -p $out/include/${pname} cp *.h $out/include/${pname}/ + mkdir -p $out/share/varnam/schemes + echo ${toString (lib.lists.forEach schemeSrcs (scheme: "${scheme}/*.vst"))} + cp ${toString (lib.lists.forEach schemeSrcs (scheme: "${scheme}/*.vst"))} $out/share/varnam/schemes/ + runHook postInstall ''; diff --git a/govarnam/schemes.nix b/govarnam/schemes.nix new file mode 100644 index 0000000..1d5c40c --- /dev/null +++ b/govarnam/schemes.nix @@ -0,0 +1,58 @@ +{ + "as" = { + url = "https://github.com/varnamproject/schemes/releases/download/v1.8.0/as.zip"; + sha = "1skc85kwc4zvrzj7j4jbwnj1kc6662r3cypi1rgp40srmga0wvs5"; + }; + "bn" = { + url = "https://github.com/varnamproject/schemes/releases/download/v1.8.0/bn.zip"; + sha = "0ywmlhwwmm183g7rm62lfp58qrgk2wiwgxlzzpkp0g5w5n01g86i"; + }; + "gu" = { + url = "https://github.com/varnamproject/schemes/releases/download/v1.8.0/gu.zip"; + sha = "0wvjgfmyp1pqkvknc0p3x69rb5czry11gddr0spzbq68z9yqalq7"; + }; + "hi" = { + url = "https://github.com/varnamproject/schemes/releases/download/v1.8.0/hi.zip"; + sha = "09v4ld7xy1xm8qf4hr8m9fmnmzm89rqyjpn7aifp008vaws0pd7y"; + }; + "kn" = { + url = "https://github.com/varnamproject/schemes/releases/download/v1.8.0/kn.zip"; + sha = "19l9b3hy32sli3c2mll5x9akiy1nczj9m8knf221f2m1wp92i4cx"; + }; + "ml-inscript" = { + url = "https://github.com/varnamproject/schemes/releases/download/v1.8.0/ml-inscript.zip"; + sha = "0hbr4pyaa6jwxjxxrwih99510q1mb91vph75njmnrcrifs74k186"; + }; + "ml" = { + url = "https://github.com/varnamproject/schemes/releases/download/v1.8.0/ml.zip"; + sha = "0cj1ca1ynbga3cry9sgwvs0bra3i0bvjp9prg28s4nvj3jk0zdry"; + }; + "mr" = { + url = "https://github.com/varnamproject/schemes/releases/download/v1.8.0/mr.zip"; + sha = "061hc81n12zbzlp5qcfl4bf4ixv70f80x75igymlps9s8nvjm853"; + }; + "ne" = { + url = "https://github.com/varnamproject/schemes/releases/download/v1.8.0/ne.zip"; + sha = "0lcdc600cmpkdpb4k1k68wvczz4vidcj25ikzr21ml8jy861pz2m"; + }; + "or" = { + url = "https://github.com/varnamproject/schemes/releases/download/v1.8.0/or.zip"; + sha = "0ibvm3wsy0z179b3fhdba78riv8h5c47sm8xma0phhr151nmaplz"; + }; + "pa" = { + url = "https://github.com/varnamproject/schemes/releases/download/v1.8.0/pa.zip"; + sha = "06nxkz2jxd845kya8231qd2m7g9xg9q6bllb78achx09wrigv5wj"; + }; + "sa" = { + url = "https://github.com/varnamproject/schemes/releases/download/v1.8.0/sa.zip"; + sha = "1lrl23d5rgkb5lnsbdz2cqq14zvi7hi0mkvpsay03fbg97mzghx7"; + }; + "ta" = { + url = "https://github.com/varnamproject/schemes/releases/download/v1.8.0/ta.zip"; + sha = "0w14qp19b9r36aaq0wl7awdc7w5633j8x3mpx013cr0xqraqwjm1"; + }; + "te" = { + url = "https://github.com/varnamproject/schemes/releases/download/v1.8.0/te.zip"; + sha = "0mqllwi0337iwn9jy2s8piqlc9bj7a8rg1ykxfnxmyhh77vs6dax"; + }; +} diff --git a/govarnam/update.sh b/govarnam/update.sh new file mode 100755 index 0000000..e557ed9 --- /dev/null +++ b/govarnam/update.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env nix-shell +#! nix-shell -i bash --keep GITHUB_TOKEN -p nix-prefetch jq + +set -eo pipefail + +curl_args=( '--silent' ) + +# optionally takes a GITHUB_TOKEN to overcome api rate limiting. +if [ -n "$GITHUB_TOKEN" ]; then curl_args+=( --header "authorization: Bearer ${GITHUB_TOKEN}" ); fi + +# get latest release assets +curl_args+=( --url https://api.github.com/repos/varnamproject/schemes/releases/latest ) +scheme_archives=$(curl "${curl_args[@]}" | jq -r '.assets' ) + +dirname="$(dirname "$0")" + +printf '{\n' > "$dirname/schemes.nix" + +while + read -r file_path +do + name="$(basename $file_path)" + name="${name/.zip/}" + if [ $name != "source-with-lfs" ]; then + printf ' "%s" = {\n url = "%s";\n sha = "%s";\n };\n' "${name}" "$file_path" "$(nix-prefetch-url --unpack "$file_path")" >>"$dirname/schemes.nix" + fi +done < <(jq -r '.[].browser_download_url' <<<"$scheme_archives") + +printf '}\n' >> "$dirname/schemes.nix" +