gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source
https://gno.land/
Other
860 stars 348 forks source link

Request: Be able to permanently set `-home` parameter for `gnokey` #1504

Closed leohhhn closed 6 months ago

leohhhn commented 6 months ago

Description

In case a user wants to have its gnokey home dir in a different place that the default one, it would be a good UX addition for gnokey to be able to permenantly set the home dir instead of having to pass it in with every command.

Currently, the -home parameter is not persisted between calls to the gnokey binary.

thehowl commented 6 months ago

the GNOHOME environment variable?

leohhhn commented 6 months ago

I am talking specifically on the -home parameter, which stores the path to the data dir where the keypairs are stored. Not sure if it coincides with GNOHOME/GNOROOT directly.

I'm reading through gnokey code, it seems that the default is empty, ie from this snippet:

var DefaultBaseOptions = BaseOptions{
    Home:                  "",
    Remote:                "127.0.0.1:26657",
    Quiet:                 false,
    InsecurePasswordStdin: false,
    Config:                "",
}

The way gnokey infers its home parameter is very weird, and frankly I'm not sure how it works.

thehowl commented 6 months ago

I'm reading through gnokey code, it seems that the default is empty, ie from this snippet:

So, it's a bit different.

The gnokey binary doesn't actually use client.DefaultBaseOptions (the variable you posted). Instead, refer to cmd/gnokey/main.go: this one shows that the true base config used is the following:

    baseCfg := client.BaseOptions{
        Home:   gnoenv.HomeDir(),
        Remote: "127.0.0.1:26657",
    }

Ie. the default value for -home1 is gnoenv.HomeDir.

This is gnovm/pkg/gnoenv/gnohome.go. In summary: it's GNOHOME, and if it is not set it falls back to ~/.config/gno (on UNIX, on Windows it's AppData IIRC).

What we should recommend users, if they want to change their home directory permanently, is to add export GNOHOME=/path/to/gnohome in their ~/.profile. (In fact, I think we should remove the -home flag altogether, as I don't think it's something a user wants to change with each execution, but I digress)

leohhhn commented 6 months ago

Cool, thanks. I'll close this issue in favor of documenting this more clearly.