Jas-SinghFSU / HyprPanel

A Bar/Panel for Hyprland with extensive customizability.
MIT License
461 stars 34 forks source link

[Feature] Add an option to get the WeatherAPI key from a file #202

Open anotherhadi opened 2 weeks ago

anotherhadi commented 2 weeks ago

Is your feature request related to a problem? Please describe.

I want to make my system fully reproducible. I handle my secrets with nix-sops and so it would be useful to be able to read the API key from a file instead of hardcoding a key to the config file.

Describe the solution you'd like

A "menus.clock.weather.keyFile" option

Describe alternatives you've considered

Don't use the weather widget.. :(

Jas-SinghFSU commented 1 week ago

Why not export your config in Configuration > General > Config which is a file? Then you can import that file and pick up where you left off on all of your settings.

anotherhadi commented 1 week ago

Why not export your config in Configuration > General > Config which is a file? Then you can import that file and pick up where you left off on all of your settings.

My config is shared through a Nix file (publicly available: https://github.com/anotherhadi/nixy/blob/main/home/system/hyprland/hyprpanel.nix), but I don't want my API key to be in this file. Sops-nix allows me to decrypt some string and place it in a file (it overwrites this file, it doesn't allow me to edit a JSON value inside an existing file)

With this keyFile, I could hardcode the file path without exposing my API key, and the keyFile will be generated by sops-nix (For reproducibility, I don't want to edit the config file manually to add my API key)

anotherhadi commented 1 week ago

PS: Most Nix modules with passwords/keys work this way If the keyFile is not found, it should take the key string value and not return a keyFile not found error! (So the users using others config without the sops private key won't get any errors)

Jas-SinghFSU commented 1 week ago

Ahh, yea that's totally reasonable. There is currently a configuration if you look in options.ts:

            weather: {
                interval: opt(60000),
                unit: opt<UnitType>("imperial"),
                location: opt("Los Angeles"),
                key: opt<string>(
                    JSON.parse(Utils.readFile(`${App.configDir}/.weather.json`) || "{}")?.weather_api_key || "",
                ),
            }

Where if you have a .weather.json file in your ags directory, it takes the weather_api_key value for the api key. But this isn 't super useful via nix. I'll have to look into the right approach to this.

anotherhadi commented 1 week ago

Ahh, yea that's totally reasonable. There is currently a configuration if you look in options.ts:


            weather: {

                interval: opt(60000),

                unit: opt<UnitType>("imperial"),

                location: opt("Los Angeles"),

                key: opt<string>(

                    JSON.parse(Utils.readFile(`${App.configDir}/.weather.json`) || "{}")?.weather_api_key || "",

                ),

            }

Where if you have a .weather.json file in your ags directory, it takes the weather_api_key value for the api key. But this isn 't super useful via nix. I'll have to look into the right approach to this.

Oh, I actually think that solve my issue, my encrypted file would be "weather_api_key":".." and decrypted to the path "$CONFID_DIR/.weather.json"! I'll try this in a minute

anotherhadi commented 1 week ago

Oh wait mb, in nix the ags folder isn't in .config/... but in the nix store, so wouldn't work ig