Proper way to access `share` folder

Keepassxc puts in the $out/share/keepassxc/wordlists folder a list of files containing words usable to generate new passphrase (for instance you can put one file per language).

I tried to add my own list of files by creating a new package that would populate this same folder:

{ pkgs, config, ...}:
  # I made that dict by selecting non derivative (only infinitive, singular, as far as I could)
  # french words that are "frequent" in the sense that they appear enough times (not that much)
  # in a list of files I downloaded
  keepassxc_french_dict = pkgs.stdenv.mkDerivation {
    name = "keepassxc_french_dict";
    src = ./french_frequent_no_derivations_11508_words.txt;
    unpackPhase = ''
      cp $src french_frequent_no_derivations_11508_words.txt
    buildPhase = "";
    installPhase = ''
      mkdir -p $out/share/keepassxc/wordlists/
      cp french_frequent_no_derivations_11508_words.txt $out/share/keepassxc/wordlists/
  environment.systemPackages = with pkgs; [

and indeed it does work:

$  ls /run/current-system/sw/share/keepassxc/wordlists
eff_large.wordlist  french_frequent_no_derivations_11508_words.wordlist

Unfortunately this new file is not recognized by KeepassXC. My guess is that KeepassXC picks the file in /nix/store instead of /run/...:

/run/current-system/sw/share/keepassxc/wordlists$ ls -al
total 34
dr-xr-xr-x 2 root root   4 janv.  1  1970 .
dr-xr-xr-x 3 root root   6 janv.  1  1970 ..
lrwxrwxrwx 1 root root 104 janv.  1  1970 eff_large.wordlist -> /nix/store/2i6wqwgs2agy2d5lyl0d0fbgadsp396y-keepassxc-2.7.1/share/keepassxc/wordlists/eff_large.wordlist
lrwxrwxrwx 1 root root 143 janv.  1  1970 french_frequent_no_derivations_11508_words.wordlist -> /nix/store/py0njcgci2kf5qq8xl2fzs35ba43rldd-keepassxc_french_dict/share/keepassxc/wordlists/french_frequent_no_derivations_11508_words.wordlist

But I’m not sure who is doing something wrong:

  • is it KeepassXC that should find the share folder in a different way (how? Is there an environment variable for this? I found XDG_DATA_DIR that seems to contain such things, but I’m not sure if it’s the appropriate way to do that… Also if a program is not installed globally on the system, wouldn’t it be a problem to use /run as it won’t be populated with the locally installed program? Or should keepass first find files in the /nix/store (configured via CMAKE) and then in /run (using e.g. the XDG_DATA_DIR variable)?)
  • is it NixOs that should provide a different path for the share folder via CMAKE (then I guess it would create quite a lot of issues, not only the one of the first solution but also /run is certainly not writable)
  • is it me that should install my dictionaries differently? How should I proceed? Should I override the derivation (and lose the binary cache features?)?

Note that I created an issue here

I think that for this kind of data, the app following XDG basedir spec (XDG data files paths) in addition to the installation directory is the proper solution.

1 Like

Thanks, I agree that it’s the one that makes the most sense. Thanks!