• AllHailTheSheep@sh.itjust.works
    link
    fedilink
    arrow-up
    2
    ·
    edit-2
    22 hours ago

    my thing is that it becomes hard to automate things. you install a package in a toolbox, then if you want to use that package in a script you must first enter the toolbox manually. I wish there was a way to enter the toolboxes programmatically for scripting.

    edit: I was incorrect, see below comment

    • entwine@programming.dev
      link
      fedilink
      arrow-up
      8
      ·
      23 hours ago

      You can, and should do that. Here’s what that looks like: toolbox run -c <toolbox-name> <command>

      All of my development tools are in a toolbox, including my IDE (Sublime Text). I created a standard .desktop file so that I can launch it like any other application, and it works perfectly, with a proper Icon and everything. Example:

      [Desktop Entry]
      Version=1.0
      Type=Application
      Name=Sublime Text
      GenericName=Text Editor
      Comment=Sophisticated text editor for code, markup and prose
      Exec=/usr/bin/toolbox run -c devel /opt/sublime_text/sublime_text %F
      Terminal=false
      MimeType=text/plain;
      Icon=/home/user/.local/share/applications/SublimeText.png
      Categories=TextEditor;Development;
      StartupNotify=true
      StartupWMClass=sublime_text
      

      To run something on the host from inside a toolbox, you can use flatpak-spawn:

      $ toolbox enter ...
      $ flatpak-spawn --host <command> <args>
      

      You can even use that to (awkwardly) run something in another toolbox using the same command above:

      flatpak-spawn --host toolbox run -c <other-container> <command>
      

      Sublime text specifically has support for custom build commands. Sometimes, I’m using it to develop something in a different toolbox than the one sublime is installed in. So in my custom build script for the project, I add a check to enter the correct toolbox before executing the build. Here’s what that looks like:

      TARGET_TOOLBOX=example
      source /run/.containerenv
      if [ "$name" != "${TARGET_TOOLBOX}" ]; then
      	echo "SWITCHING CONTAINER $0 $@";
      	flatpak-spawn --host toolbox run --container ${TARGET_TOOLBOX} /usr/bin/env zsh -c "$0 $@";
      	exit 0;
      fi
      
      #proceed with build...
      

      This container/toolbox workflow is far superior to anything else, as it makes it trivial to quickly test whether your code works on a different distros/versions. It all just works with your existing tooling/local workflows once you learn how to work with the tools. There really is nothing you can’t do.

      …and that’s for development, which is the most difficult scenario for this type of thing. For regular every day users, immutability just works without requiring people to learn anything new besides reaching for flatpak instead of apt/dnf/pacman/etc.

      • AllHailTheSheep@sh.itjust.works
        link
        fedilink
        arrow-up
        3
        ·
        22 hours ago

        you’re a lifesaver!! I swear I looked pretty hard on the internet for this exact solution without success. my apologies!!

        thanks for the info!!!