Jump to content

Anki: Difference between revisions

From Official NixOS Wiki
Both unstable and stable host anki 25.09.2 and anki-bin 25.02.5 so anki is newer now
DHCP (talk | contribs)
add syntax highlighting
 
(One intermediate revision by one other user not shown)
Line 6: Line 6:
<code>anki</code> is recommended over <code>anki-bin</code>, due to <code>anki-bin</code> being out of date (at the time of writing). Using old versions of <code>anki-bin</code> may lead to decks being incompatible with newer versions.
<code>anki</code> is recommended over <code>anki-bin</code>, due to <code>anki-bin</code> being out of date (at the time of writing). Using old versions of <code>anki-bin</code> may lead to decks being incompatible with newer versions.


;NixOs
;NixOS
environment.systemPackages = [
 
  pkgs.anki
{{File|name=/etc/nixos/configuration.nix|lang=nix|3=
];
environment.systemPackages = [
  pkgs.anki
];}}


;nix-shell
;nix-shell
<code>$ nix-shell -p anki</code>
<syntaxhighlight lang="console">
$ nix-shell -p anki
</syntaxhighlight>


== Installing Addons ==
== Installing Addons ==
Additional addons can be installed using the following syntax:
Additional addons can be installed using the following syntax:


;NixOs
;NixOS
environment.systemPackages = [
 
  (pkgs.anki.withAddons [
{{File|name=/etc/nixos/configuration.nix|lang=nix|3=
    pkgs.ankiAddons.passfail2
environment.systemPackages = [
  ])
  (pkgs.anki.withAddons [
];
    pkgs.ankiAddons.passfail2
  ])
];}}


Note that as of writing, <code>anki-bin</code> does not support installing addons in this way.
Note that as of writing, <code>anki-bin</code> does not support installing addons in this way.
Line 29: Line 35:
Addons can be configured using <code>.withConfig</code>:
Addons can be configured using <code>.withConfig</code>:


;NixOs
;NixOS
environment.systemPackages = [
 
  (pkgs.anki.withAddons [
{{File|name=/etc/nixos/configuration.nix|lang=nix|3=
    (pkgs.ankiAddons.passfail2.withConfig {
environment.systemPackages = [
      config = {
  (pkgs.anki.withAddons [
        again_button_name = "Incorrect";
    (pkgs.ankiAddons.passfail2.withConfig {
        good_button_name = "Correct";
      config = {
      };
        again_button_name = "Incorrect";
    })
        good_button_name = "Correct";
  ])
      };
];
    })
  ])
];}}


[[Category:Applications]]
[[Category:Applications]]
== Self Hosting ==
You can self host an instance of anki-sync-server via the NixOS module.
The default port for this service is 27701.
The most simplest setup for it you can have is like below:
;NixOS
<syntaxhighlight lang=nix>
services.anki-sync-server = {
  enable = true;
  address = "0.0.0.0";
  openFirewall = true;
  users = [
    {
      username = "bob";
      password = "password";
    }
  ];
};
</syntaxhighlight>
You would then access the self hosted instance by changing it on the anki app you're using, but make sure to write as <code>http://ReplaceLocalIPHere:27701/</code> it is necessary to have the <code>/</code> at the end on the clients. After doing that, attempt to sync and when asked for log in details do, in this case <code>bob</code> as the email address and <code>password</code> as the password and it will work.
Note: This does let anyone on your local network access your anki-sync-server instance and it is exposed under http. It also exposes your password in plain text on the server. A better recommendation is to use the <code>passwordFile</code> option.
=== Reverse Proxy ===
You can reverse proxy anki-sync-server to make sure it's running under a https connection and in order to restrict it more to your vpn of choice.
A complete setup for that using caddy as the reverse proxy would be:
;NixOS
<syntaxhighlight lang=nix>
services.anki-sync-server = {
  enable = true;
  address = "127.0.0.1";
  users = [
    {
      username = "bob";
      password = "password";
    }
  ];
};
services.caddy.virtualHosts."anki.custom.domain".extraConfig = ''
  reverse_proxy ${config.services.anki-sync-server.address}:${builtins.toString config.services.anki-sync-server.port}
'';
</syntaxhighlight>
Then to access that on your anki clients, you change the sync server to <code>https://anki.custom.domain/</code> that end <code>/</code> is important in order to get the clients working properly. Then you would log in with the "email address" as <code>bob</code> and the password as <code>password</code>
Note: It is still recommended to use the <code>passwordFile</code> option over the plain text <code>password</code> option as the latter option stores it in plain text in the nix store on the server.

Latest revision as of 12:53, 1 June 2026

Anki is a spaced repetition system (SRS) commonly used to learn new languages. Information is placed on individual flashcards, which are sorted into decks. Anki is extensible using Python addons.

In addition to the desktop software, Anki has an iOS app, Android app, and web interface available. Decks/flashcards can be synced using a self hosted instance of anki-sync-server or an AnkiWeb account.

Installation

anki is recommended over anki-bin, due to anki-bin being out of date (at the time of writing). Using old versions of anki-bin may lead to decks being incompatible with newer versions.

NixOS
❄︎ /etc/nixos/configuration.nix
environment.systemPackages = [
  pkgs.anki
];
nix-shell
$ nix-shell -p anki

Installing Addons

Additional addons can be installed using the following syntax:

NixOS
❄︎ /etc/nixos/configuration.nix
environment.systemPackages = [
  (pkgs.anki.withAddons [
    pkgs.ankiAddons.passfail2
  ])
];

Note that as of writing, anki-bin does not support installing addons in this way.

Configuring Addons

Addons can be configured using .withConfig:

NixOS
❄︎ /etc/nixos/configuration.nix
environment.systemPackages = [
  (pkgs.anki.withAddons [
    (pkgs.ankiAddons.passfail2.withConfig {
      config = {
        again_button_name = "Incorrect";
        good_button_name = "Correct";
      };
    })
  ])
];

Self Hosting

You can self host an instance of anki-sync-server via the NixOS module. The default port for this service is 27701. The most simplest setup for it you can have is like below:

NixOS
services.anki-sync-server = {
  enable = true;
  address = "0.0.0.0";
  openFirewall = true;
  users = [
    {
       username = "bob";
       password = "password";
    }
  ];
};

You would then access the self hosted instance by changing it on the anki app you're using, but make sure to write as http://ReplaceLocalIPHere:27701/ it is necessary to have the / at the end on the clients. After doing that, attempt to sync and when asked for log in details do, in this case bob as the email address and password as the password and it will work. Note: This does let anyone on your local network access your anki-sync-server instance and it is exposed under http. It also exposes your password in plain text on the server. A better recommendation is to use the passwordFile option.

Reverse Proxy

You can reverse proxy anki-sync-server to make sure it's running under a https connection and in order to restrict it more to your vpn of choice. A complete setup for that using caddy as the reverse proxy would be:

NixOS
services.anki-sync-server = {
  enable = true;
  address = "127.0.0.1";
  users = [
    {
      username = "bob";
      password = "password";
    }
  ];
};
services.caddy.virtualHosts."anki.custom.domain".extraConfig = ''
  reverse_proxy ${config.services.anki-sync-server.address}:${builtins.toString config.services.anki-sync-server.port}
'';

Then to access that on your anki clients, you change the sync server to https://anki.custom.domain/ that end / is important in order to get the clients working properly. Then you would log in with the "email address" as bob and the password as password Note: It is still recommended to use the passwordFile option over the plain text password option as the latter option stores it in plain text in the nix store on the server.