Moving .gnucash and friends from $HOME to XDG_DATA_HOME (and impact on other applications like KMyMoney)

Geert Janssens geert.gnucash at
Sat Aug 26 16:07:50 EDT 2017

On vrijdag 25 augustus 2017 16:22:27 CEST John Ralls wrote:
> For the CMake/configure option my thought is to have something like
> --set-default-user-data-dir which would take a single path string to be
> appended to $HOME and if defined would remove the XDG-checking code, but
> you're right that packagers can also use a post-install hook to set the
> environment variables either in  /etc/gnucash/environment,
> /etc/bash_profile, or in the desktop file. On the other hand you could also
> just go that route directly and stuff the appropriate values into
> gnucash/environment at build time and leave the runtime code alone.
> This code is for gnucash rather than libgnucash, right? In that case there's
> no point in removing glib until we're also ready to remove gtk and we'll
> just replace the cross-platform utility functions like that with whatever
> functions the replacement framework provides. I wouldn't waste time on
> hand-rolling replacements unless there's a good reason to.
> Regards,
> John Ralls

I have just pushed my work to master.

For the gnucash user-level application data (former $HOME/.gnucash), it 
behaves as follows:
1. if GNC_DATA_HOME is set gnucash will try to use this. If this directory 
doesn't exist, gnucash will try to create it.
2. If that fails or GNC_DATA_HOME is not set gnucash will try to use a 
platform dependent default instead. These defaults are:
- Linux: $XDG_DATA_HOME/GnuCash (or its default $HOME/.local/share/GnuCash if 
the environment variable isn't set)
- Windows: User's AppData(Roaming)\GnuCash
- OS X/Quarz:  NSApplicationSupportDirectory/GnuCash (which by default expands 
to $HOME/Library/Application Support/GnuCash)
3. If those directories don't work for some reason, gnucash will try to reuse 
an existing $HOME/.gnucash (but not create it - we want to drop this 
4. If that also fails, <temp-dir>/GnuCash will be used instead.
5. If that also fails, gnucash will halt.

Note $HOME/.gnucash is no longer the default. The first time a user will run 
gnucash 2.8, data will be migrated from there to the new location. Obviously 
this will only happen if the old location exists. So for new users, nothing 
will happen. Normally for OS X/Quarz users nothing should happen either 
because the location hasn't changed there. When the migration happens the user 
will be informed during startup of the program.

As for AqBanking, in the end I decided to not do anything to relocate the 
config dir by default. Instead I have amended the environment file (typically 
in /etc/gnucash/environment). It now mentions you can set the AQBANKING_HOME 
environment variable to use a different location. That allows each user to 
choose for him/her self if/when to migrate. The user should move the directory 
him/her self at that moment.

The environment file had one big drawback, namely it's overwritten with each 
install/update of the gnucash application. So changing values in there had to 
be done over and over again. To solve this I have chosen to support a second 
environment file named "environment.local". This file can be created by the 
user right next to the installed environment file and has the same format (a 
[Variables] group with variables to set). It will be evaluated after the 
installed environment file and can hence be used to override it. It's still 
system level, so to create/manipulate it admin privileges are required.

Some notes:
* I have done my best to write some cocoa code to get the 
NSApplicationSupportDirectory value. I don't know if it works though. I no 
longer have a system to test this on. John if not, feel free to correct my 
* Similarly I haven't tested this on Windows either yet. Will do so one of the 
following days.
* The code goes through a few hoops to avoid creating new directories unless 
explicitly asked. This is because guile compilation of some of our report 
related files will actually *run* this filepath code. I don't want migrations 
to happen at build time. However if no directories are found the code will 
abort. I didn't want to remove the (pre-existing) abort because I haven't 
checked if the rest of gnucash can handle non-existent paths. So during build 
a fake userdata directory is created in the system's temp directory.

That's all I can think of for now. Please report any issues you find.


More information about the gnucash-devel mailing list