ciao-lang/ciao

ensure_datadir/2 fails for non-local installation of Ciao

ony opened this issue · 2 comments

ony commented

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

Related code seems to be:

get_datadir(RelPath, D) :-
% Otherwise, use a local data path
data_root_dir(Dir0),
D = ~path_concat(Dir0, RelPath).

:- export(site_root_dir/1).
% Files for HTTP serving
site_root_dir := Path :-
Bundle = core, % TODO: allow any bundle
Path = ~bundle_path(Bundle, builddir, 'site').
:- export(data_root_dir/1).
% Files for per-bundle persistence
data_root_dir := Path :-
Bundle = core, % TODO: allow any bundle
Path = ~bundle_path(Bundle, builddir, 'data').

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

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.