Copy files to /var broke my snap builds

I’m currently working on building this application: witch_craft Snapcraft.yaml.

However, I’ve encountered two major issues that I can’t seem to resolve:

  1. I need to copy files to /var/witch_craft/, but I’m unsure how to do this within the Snapcraft build.
  2. Although the snap builds and installs (the snap file is around 1GB, by the way), it won’t execute.

I found a related issue on the Snapcraft forum: Snap run app cannot find app, where Alan_g mentions: “That error indicates the snap has been packaged incorrectly. That needs to be fixed by the packager.” I believe this is likely the problem, but I’m not sure what I’ve done wrong in the packaging process.

The snap: Install witchcraft-cybersecurity on Linux | Snap Store

During the snap build this isn’t reasonable. Even if you were to copy files to /var/... they would be on the build host/VM, and not included in the snap. They need to be in $CRAFT_PRIME/var/....

At runtime it is best if you can configure the application to find these files in $SNAP/var/.... But that isn’t always possible. The next option is to use a layouts section in the snapcraft recipe to bind mount $SNAP/var/... as /var/....

Good luck!

1 Like

I found the solution, and it’s much simpler than I thought. However, I need to point out that the Snap documentation is lacking and confusing, more than it should be.

anyway, thank you @alan_g

environment:
  WITCH_SPELLS_ROOT_DIR: $SNAP/var/witch_craft/witch_spells/

parts:
  witchspells:
    source: ./witch_spells/
    plugin: dump

Now my app can use environment variable WITCH_SPELLS_ROOT_DIR WITCH_SPELLS_ROOT_DIR=/snap/witchcraft-cybersecurity/x2/var/witch_craft/witch_spells/