How to specify runtime paths during build stage

Hi,

I am building an nginx part, as part of my snap. I specify my desired install directories (e.g. prefix, sbin-path, config file paths, etc) with the autotools-configure-parameters directive as follows:

nginx:
    plugin: autotools
    source: http://nginx.org/download/nginx-1.25.3.tar.gz
    build-packages:
      - libpcre3-dev
      - libssl-dev
      - pkg-config
    autotools-configure-parameters:
      - --prefix=/usr/nginx
      - --sbin-path=/bin/nginx
      - --modules-path=/usr/nginx/modules
      - --conf-path=/usr/nginx/conf/nginx.conf
      - --error-log-path=/var/log/nginx/error.log
      - --http-log-path=/var/log/nginx/access.log
      - --pid-path=/var/log/nginx/nginx.pid
      - --lock-path=/var/log/nginx/nginx.lock
      - --with-http_ssl_module
      - --add-module=extras/nginx-rtmp-module

However, when running the snap, nginx looks for the config files at the absolute path /usr/nginx/conf/nginx.conf for example. Obviously, there is no system-wide nginx installed at /usr as it is installed in /snap/<snap-name>/current/usr. I tried using organize to fix this issue by doing:

nginx:
    plugin: autotools
    source: http://nginx.org/download/nginx-1.25.3.tar.gz
    organize:
      snap/<snap-name>/current/usr: usr
      snap/<snap-name>/current/bin: bin
      snap/<snap-name>/current/var: var
      snap/<snap-name>/current/etc: etc
    build-packages:
      - libpcre3-dev
      - libssl-dev
      - pkg-config
    autotools-configure-parameters:
      - --prefix=/snap/<snap-name>/current/usr/nginx
      - --sbin-path=/snap/<snap-name>/current/bin/nginx
      - --modules-path=/snap/<snap-name>/current/usr/nginx/modules
      - --conf-path=/snap/<snap-name>/current/usr/nginx/conf/nginx.conf
      - --error-log-path=/snap/<snap-name>/current/var/log/nginx/error.log
      - --http-log-path=/snap/<snap-name>/current/var/log/nginx/access.log
      - --pid-path=/snap/<snap-name>/current/var/log/nginx/nginx.pid
      - --lock-path=/snap/<snap-name>/current/var/log/nginx/nginx.lock
      - --with-http_ssl_module
      - --add-module=extras/nginx-rtmp-module

Now, the issue with this approach is that the files are installed into the correct directories within the snap, but during runtime nginx tries looking for the files at /snap/<snap-name>/current/... and does not replace current with the snap revision, hence not finding them.

What is the proper way of specifying these directories for autotools so that they are correctly accessed during runtime?

Cheers,

Ramin

Why do you feel you need this in the first place?

You should just use --prefix=/usr (so it doesn’t end up in /usr/local) and then add layouts to your snapcraft.yaml as needed to re-map the files in /usr/share and /etc … never hardcode /snap/foo in your binaries, this will just cause trouble down the road…

I’m loading custom modules and configs, so I thought I’d specify where those files would be placed later on to avoid any mismatches. I suppose it has proven more troublesome than beneficial.

I will try only the —prefix and hunt down where the other files end up (docs have been inconsistent, another reason why I decided to hardcore paths).

On a side note, is there a way of doing such a thing with snaps at all? Assuming making a wrapper is not an option.

Thanks,

Ramin