ciao-lang / ciao

Ciao is a modern Prolog implementation that builds up from a logic-based simple kernel designed to be portable, extensible, and modular.
https://ciao-lang.org
GNU Lesser General Public License v3.0
272 stars 21 forks source link

ensure_datadir/2 fails for non-local installation of Ciao #50

Open ony opened 2 years ago

ony commented 2 years ago

Looks like persdb/datadir tries to use system path for data dir (probably relative to core/builder bundles or CIAOROOT folders).

Can be reproduced with Nix packaged version (example for Flakes flavor):

nix run nixpkgs\#ciao
use_module(library(persdb/datadir)). ensure_datadir('learn-ciao', Dir).
zsh%  nix run nixpkgs\#ciao
Ciao 1.20.0 [LINUXx86_64]
?- use_module(library(persdb/datadir)). ensure_datadir('learn-ciao', Dir).

yes
?- {ERROR: system:make_directory/2, arg 1 - system error: Read-only file system}

In NixOS packages installed at location that is perceived as read-only for normal users.

P.S. This at least affects ciaopp. See ciao-lang/ciaopp#2

ony commented 2 years ago

Related code seems to be:

https://github.com/ciao-lang/ciao/blob/f6d7b1539a9a783cf26e2f54feda92ec6d725da9/core/library/persdb/datadir.pl#L64-L67

https://github.com/ciao-lang/ciao/blob/f6d7b1539a9a783cf26e2f54feda92ec6d725da9/builder/src/config_common.pl#L82-L92

With core bundle being installed into system location and not allowed for write - these setup is not going to fully work.

Shouldn't persistence always fallback to something like $XDG_STATE_HOME/~/.local/state (maybe with some versioning) on Unix. If persdb indeed allows multi-user access with updates, then it probably should use /var/db with appropriate permissions install.

jfmc commented 2 years ago

Thank you @ony for the fantastic analysis of the problem and your proposed solution. Indeed Ciao needs a few user-writable directories for caching compilation and analysis data. Also commands like ciao get ... requires a user-writable directory to download and compile sources. This is well tested for local installations but not for system-wide configurations.

It will be awesome to finally fix those issues. I've seen that other systems (like npm already have or had) issues with globally installing packages since nix store is immutable. Most of the solutions I've seen are a mix of global immutable installation + local home subdirectory for packages. We'd really appreciate if you can point us to any good accepted solution for those problems, specially if it works both in different Linux distributions and macOS.