Cannot use nmcli on electron snap app

I have an electron app which i am trying to package it as a kiosk following this documentation i am able to snap the app it launches fine,
i am using node-wifi which internally uses nmcli looks like i am unable to access/call nmcli i have seen a bunch of issues mentioning to use network-manager i tried adding it to build-packages and creating a new part like this:

plugin: nil
- network-manager
usr/bin/nmcli: bin/nmcli

but nothing seems to be working from me, from node-wifi i get {"killed":false,"code":1,"signal":null,"cmd":"nmcli --terse --fields active,ssid,bssid,mode,chan,freq,signal,security,wpa-flags,rsn-flags,device device wifi"}

Thanks in advance.

What plugs do you have defined, and are they connected? use snap connections to see if they’re connected.

nmcli should work fine if you define the network-manager plug for your app so the snap is able to connect to a running network manager via dbus …

note that this indeed means you need to have an network-manager instance running on the host already …

so in case you are using a classic server install to run your kiosk, you want to install the network-manager deb on the host, if you use UbuntuCore you want to install the network-manager snap and connect your app to it.

Thank you for super fast response,
I am new to building snaps so clearly not sure about what you are asking
here is the sample snapcraft.yaml i have.

name: nd
version: '0.1'
summary: nd Staging
description: |
base: core18
confinement: strict
grade: devel

    command: desktop-launch "$SNAP/nd/nd" "--no-sandbox"
    - browser-support
    - network
    - network-bind
    - opengl
    - pulseaudio
    - x11
    - network-manager

      plugin: nil
        - network-manager
        usr/bin/nmcli: bin/nmcli
    plugin: python
    python-version: python2
    python-packages: [numpy]
    plugin: nodejs
    nodejs-version: 13.5.0
    source-type: local
    nodejs-package-manager: npm
    source: .
    after: [desktop-gtk3]
    override-build: |
        which node
        echo "helllo"
        npm config set user 0
        npm config set unsafe-perm true
        node --version
        npm --version
          "i386-linux-gnu") ARCH="ia32";;
          "x86_64-linux-gnu") ARCH="x64";;
          "arm-linux-gnueabihf") ARCH="armv7l";;
          "aarch64-linux-gnu") ARCH="arm64";;
          *) echo "ERROR: electron does not support the '$SNAPCRAFT_ARCH_TRIPLET' architecture" && exit 1;;
        npm install
        npm run clean &&
        npm run build-staging &&
        ./node_modules/.bin/electron-packager . --overwrite --platform=linux --arch=$ARCH --output=release-build --prune=true
        cp -v -R ./ND-linux-$ARCH $SNAPCRAFT_PART_INSTALL/nd
    - libasound2
    - libgconf-2-4
    - libnss3
    - libx11-xcb1
    - libxss1
    - libxtst6

    - unzip
    - python2.7
    - network-manager

  # Adapted from snapcraft-desktop-helpers
    source-subdir: gtk
    plugin: make
    make-parameters: ["FLAVOR=gtk3"]
      - build-essential
      - libgtk-3-dev
      - libxkbcommon0  # XKB_CONFIG_ROOT
      - ttf-ubuntu-font-family
      - dmz-cursor-theme
      - light-themes
      - adwaita-icon-theme
      - gnome-themes-standard
      - shared-mime-info
      - libgtk-3-0
      - libgdk-pixbuf2.0-0
      - libglib2.0-bin
      - libgtk-3-bin
      - unity-gtk3-module
      - libappindicator3-1
      - locales-all
      - xdg-user-dirs
      - ibus-gtk3
      - libibus-1.0-5

and i already have network-manager on my ubuntu nmcli commands works fine here .

Thanks in advance .

and is your network-manager interface connected (you need to do this manually, it does not auto-connect) ?

to check connections of your app, run the command that @lucyllewy suggested above:

snap connections nd 

if it is not connected, use:

snap connect nd:network-manager

(btw, i’m not sure if the store actually allows two letter package names)

1 Like

@ogra thanks, it worked,
the app name isn’t nd i just put it there as it is small .

I have one more doubt i came from electron-builder where i had option to copy some static files to location using extraResources is there a way to specify that on snapcraft.yaml file as well ?

And also is there a way i can specify some place to create my db? when installed using deb the user path is ~/.config/nd/sqlite.db here it is /snap/nd/x1/..... but everytime i snap remove this location is deleted and data is lost but deb files the location is not cleared .

Thanks in advance

iirc electron-packager allows specifying that via a commandline flag or in package.json:

keeping user data around should be possible via (automatic) snapshots: