Pass flags during snap installation

I want to pass few service environment variables as command flags during snap installation. Is the following approach possible?

sudo snap install mysnap --flag1 --flag2 --flag3=value

No, this is not supported. What is your use case?

I have a use case to pass certain environment variables (for configuration) by the end user to snap service before installation of my snap. Is there any way I can provide this feature?

No this is not supported. AFAIK most snaps which are services, store configuration in either $SNAP_DATA or $SNAP_COMMON. If configuration is required for your service to work properly, you can use install-mode: disable and then the user can configure the service before starting it manually. See

Thanks. This is mostly for automating the installation as much as possible. Also I was thinking of taking the inputs using ‘install’ hook. Like this.

sudo snap install mysnap

Enter flag1
Enter flag2

Installing snap...

Then afterwards if someone wants to change the configuration again.

$ sudo snap set mysnap flags.flag1=value1
$ sudo snap get mysnap flags

Key           Value
flags.flag1   value1
flags.flag2   value2

Is this approach possible?

I’m not sure where the Enter thing comes from. The hooks don’t get access to tty, so there’s no way a hook could stop the installation process and wait for user’s input.

I would suggest using install-mode: disable, so the workflow is like:

snap install mysnap
snap set mysnap ...
snap start mysnap  # this is where your service starts