Hi, On June 5, 2025 9:15:08 AM GMT+02:00, nik gaffney <n...@fo.am> wrote: >On 2025-06-04 22:14, Rutherther wrote: >> >>> Is there a recommended way for a package to set environment variables >>> that should persist after install? >> >> The only way to do that is search paths. Those point to a folder in the >> profile you install to. No other mechanism is supported for packages to >> 'set' something in user's environment. See the search-paths and >> native-search-paths fields of packages. > >Thanks. Looks like search-paths could work in this case. > >> You haven't shared much details, so just a heads up - keep in mind that >> it's much better to wrap programs (script setting env vars that runs the >> program) rather than to export environment to user if that is possible. > >In more detail, i'm using metaphlan for metagenomic profiling of microboime >data which requires some large databases (generally 10~100s of GB) installed. >the program has a command line arg to download tar & md5, install databases >(which can vary depending on input) & check integrity. > >The database install doesn't work without modification, since the default path >in the store is read only. The path can be set by an env var or an arg at >runtime. > >There appear to be a few ways around this i can see >- set a VAR in the user profile (which is the way i'm working currently) >- use --db_dir PATH for every invocation (fragile) >- make a package definition for each db and add paths somewhere? >- patch the --install command to print a msg about manual setup >- wrap the command as suggested above and set VAR for db path > >The option of creating package definitions for each db (or single package with >multiple outputs?) seems most guix-like but i'm unclear about how metaphlan >could easily find the data installed by other guix packages?
Okay, then I think search paths are actually prefered - the user can choose what database to install. Does the variable support multiple database directories, like by splitting with :? If so, then that's perfect, if not, it is a bit worse, you will need to set separator of search-path-specification to #f and only one profile will be supported, ie. If someone installs the metaphlan and databases A, B, then invoking shell with metaphlan and database C will leave you with dayabase C only instead of A, B and C. For example if you put databases to share/metaphlan/databases output path of package, you could set the search path for VAR to that. Then you guix shell/install metaphlan metaphlan-database-X, and you will get the env var set to the profile with both metaphlan and metaphlan database. You can try this with something like python, ie guix shell python python-numpy, then check GUIX_PYTHONPATH. You can add --search-paths to guix shell to see the search paths produced by the shell. See 9.8 Search Paths > >Wrapping the command in a shell script that sets VAR & calls metaphlan could >work, is there a simple example somewhere in the guix tree? Yes, wrapping is used in guix, see wrap-program procedure, you can grep guix source for examples. Rutherther > >regards, >nik > > >