ryantm / agenix

age-encrypted secrets for NixOS and Home manager
https://matrix.to/#/#agenix:nixos.org
Creative Commons Zero v1.0 Universal
1.34k stars 108 forks source link

fix(home): shellcheck failure for fixed secretsDir #195

Closed Eisfunke closed 9 months ago

Eisfunke commented 10 months ago

If you set secretsDir in the home-manager module to a fixed path containing no env variable, the building of the mount script will fail with shellcheck warnings like these (for /home/eisfunke/.agenix as secretsDir):

In /nix/store/sh4igrd310v01nlfdgw9fw7qb9ck30wm-agenix-home-manager-mount-secrets/bin/agenix-home-manager-mount-secrets line 101:
[ "/home/eisfunke/.agenix/nixNetrc" != "/home/eisfunke/.agenix/nixNetrc" ] && mkdir -p "$(dirname "/home/eisfunke/.agenix/nixNetrc")"
                                    ^-- SC2050 (warning): This expression is constant. Did you forget the $ on a variable?

In /nix/store/sh4igrd310v01nlfdgw9fw7qb9ck30wm-agenix-home-manager-mount-secrets/bin/agenix-home-manager-mount-secrets line 112:
[ "/home/eisfunke/.agenix/nixNetrc" != "/home/eisfunke/.agenix/nixNetrc" ] && ln -sfn "/home/eisfunke/.agenix/nixNetrc" "/home/eisfunke/.agenix/nixNetrc"
                                    ^-- SC2050 (warning): This expression is constant. Did you forget the $ on a variable?

This is a problem as not having an env var in my secretsDir was the entire reason that I modified it at all, because not all applications accept env vars in paths (e.g. my usecase: the Nix config won't resolve the env vars net-rc-file which I want to set to an agenix secret).

Ignoring SC2050 in the corresponding lines in age-home.nix fixed this for me.

Eisfunke commented 10 months ago

CI failure seems to be unrelated.

n8henrie commented 9 months ago

I think this makes sense to silence a useless warning -- that warning just complains that a user is comparing two static strings e.g. if [ "foo" = "bar" ] which normally would be an error, but in our case these strings are being created in the above context by nix and therefore could differ.

Eisfunke commented 9 months ago

Thank you!