Unverified Commit a03b958c authored by Arne Keller's avatar Arne Keller Committed by GitHub
Browse files

anki: add withAddons (#404045)

parents 3b76d8cc e9216c0d
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -12543,6 +12543,13 @@
    githubId = 39434424;
    name = "Felix Springer";
  };
  junestepp = {
    email = "git@junestepp.me";
    github = "junestepp";
    githubId = 26205306;
    name = "June Stepp";
    keys = [ { fingerprint = "2561 0243 2233 CFE6 E13E  3C33 348C 6EB3 39AE C582"; } ];
  };
  junjihashimoto = {
    email = "junji.hashimoto@gmail.com";
    github = "junjihashimoto";
+23 −0
Original line number Diff line number Diff line
{
  lib,
  anki-utils,
  fetchFromGitHub,
  nix-update-script,
}:
anki-utils.buildAnkiAddon (finalAttrs: {
  pname = "adjust-sound-volume";
  version = "0.0.6";
  src = fetchFromGitHub {
    owner = "mnogu";
    repo = "adjust-sound-volume";
    rev = "v${finalAttrs.version}";
    hash = "sha256-6reIUz+tHKd4KQpuofLa/tIL5lCloj3yODZ8Cz29jFU=";
  };
  passthru.updateScript = nix-update-script { };
  meta = {
    description = "Add a new menu item for adjusting the sound volume";
    homepage = "https://github.com/mnogu/adjust-sound-volume";
    license = lib.licenses.agpl3Plus;
    maintainers = with lib.maintainers; [ junestepp ];
  };
})
+27 −0
Original line number Diff line number Diff line
{
  lib,
  anki-utils,
  fetchFromSourcehut,
  nix-update-script,
}:
anki-utils.buildAnkiAddon (finalAttrs: {
  pname = "anki-connect";
  version = "24.7.25.0";
  src = fetchFromSourcehut {
    owner = "~foosoft";
    repo = "anki-connect";
    rev = finalAttrs.version;
    hash = "sha256-N98EoCE/Bx+9QUQVeU64FXHXSek7ASBVv1b9ltJ4G1U=";
  };
  sourceRoot = "${finalAttrs.src.name}/plugin";
  passthru.updateScript = nix-update-script { };
  meta = {
    description = ''
      Enable external applications such as Yomichan to communicate
      with Anki over a simple HTTP API
    '';
    homepage = "https://foosoft.net/projects/anki-connect/";
    license = lib.licenses.gpl3Plus;
    maintainers = with lib.maintainers; [ junestepp ];
  };
})
+126 −0
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  symlinkJoin,
  lndir,
  formats,
  runCommand,
}:
{
  buildAnkiAddon = lib.extendMkDerivation {
    constructDrv = stdenv.mkDerivation;
    extendDrvArgs =
      finalAttrs:
      {
        pname,
        version,
        src,
        sourceRoot ? "",
        configurePhase ? ''
          runHook preConfigure
          runHook postConfigure
        '',
        buildPhase ? ''
          runHook preBuild
          runHook postBuild
        '',
        dontPatchELF ? true,
        dontStrip ? true,
        nativeBuildInputs ? [ ],
        passthru ? { },
        meta ? { },
        # Script run after "user_files" folder is populated.
        # Used when an add-on needs to process and change "user_files" based
        # on what the user added to it.
        processUserFiles ? "",
        ...
      }:
      {
        inherit
          version
          src
          sourceRoot
          configurePhase
          buildPhase
          dontPatchELF
          dontStrip
          nativeBuildInputs
          ;

        pname = "anki-addon-${pname}";

        installPrefix = "share/anki/addons/${pname}";

        installPhase = ''
          runHook preInstall

          mkdir -p "$out/$installPrefix"
          find . -mindepth 1 -maxdepth 1 | xargs -d'\n' mv -t "$out/$installPrefix/"

          runHook postInstall
        '';

        passthru = {
          withConfig =
            {
              # JSON add-on config. The available options for an add-on are in its
              # config.json file.
              # See https://addon-docs.ankiweb.net/addon-config.html#config-json
              config ? { },
              # Path to a folder to be merged with the add-on "user_files" folder.
              # See https://addon-docs.ankiweb.net/addon-config.html#user-files.
              userFiles ? null,
            }:
            let
              metaConfigFormat = formats.json { };
              addonMetaConfig = metaConfigFormat.generate "meta.json" { inherit config; };
            in
            symlinkJoin {
              pname = "${finalAttrs.pname}-with-config";
              inherit (finalAttrs) version meta;

              paths = [
                finalAttrs.finalPackage
              ];

              postBuild = ''
                cd $out/${finalAttrs.installPrefix}

                rm -f meta.json
                ln -s ${addonMetaConfig} meta.json

                mkdir -p user_files
                ${
                  if (userFiles != null) then
                    ''
                      ${lndir}/bin/lndir -silent "${userFiles}" user_files
                    ''
                  else
                    ""
                }

                ${processUserFiles}
              '';
            };
        } // passthru;

        meta = {
          platforms = lib.platforms.all;
        } // meta;
      };
  };

  buildAnkiAddonsDir =
    addonPackages:
    let
      addonDirs = map (pkg: "${pkg}/share/anki/addons") addonPackages;
      addons = lib.concatMapStringsSep " " (p: "${p}/*") addonDirs;
    in
    runCommand "anki-addons" { } ''
      mkdir $out
      [[ '${addons}' ]] || exit 0
      for addon in ${addons}; do
        ln -s "$addon" $out/
      done
    '';
}
+18 −0
Original line number Diff line number Diff line
{
  callPackage,
}:
{
  adjust-sound-volume = callPackage ./adjust-sound-volume { };

  anki-connect = callPackage ./anki-connect { };

  local-audio-yomichan = callPackage ./local-audio-yomichan { };

  passfail2 = callPackage ./passfail2 { };

  recolor = callPackage ./recolor { };

  reviewer-refocus-card = callPackage ./reviewer-refocus-card { };

  yomichan-forvo-server = callPackage ./yomichan-forvo-server { };
}
Loading