cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
3.61k stars 262 forks source link

feat(dotenv): allow passing full paths to dotenv files #1080

Open alirezamirsepassi opened 2 months ago

alirezamirsepassi commented 2 months ago

This pull request enables the dotenv integration to accept full paths to the dotenv files. Additionally, I've changed the option filename to files and moved the normalize function to the option itself using lib.toList. I've also added a warning regarding the updated option name to prevent users from breaking their environments.

P.S. I chose to use config.devenv.root instead of self because self evaluates to the nix store source tree when used in a flake configuration. Since dotenv files are typically not committed to a git repository, they won't be present after the copy.

domenkozar commented 2 months ago

This breaks on devenv with:

       error:
       error: A definition for option `dotenv.files."[definition 1-entry 1]"' is not of type `path'. Definition values:
       - In `/nix/store/virtual0000000000000000000000007-source/src/modules/integrations/dotenv.nix': ".env"

because the semantics of the paths are different, I'll think about it how to properly integrate it.

alirezamirsepassi commented 2 months ago

Hey @domenkozar

Thanks for your reply.

IMO, the path type isn't very important for the module and it can be switched back to a simple string as the file path will be verified to exist later in the module using pathExists anyway.

On second thought, we might not even want to have the path type as it will be copied to the Nix store if I'm not mistaken and it might contain some secrets that can't be managed directly/easily on the machine which later can be extracted by others. 🤔

let me know what you think. 🙏🏻

alirezamirsepassi commented 1 month ago

@domenkozar I switched the type back to string and wrapped the default value in a double quotation to avoid nix copying it to the store.

Could you try again on devenv, please?

alirezamirsepassi commented 1 month ago

@domenkozar any updates on this?

domenkozar commented 1 month ago

Thanks for the ping, CI is running

domenkozar commented 1 month ago
nix build
PATH=$PWD/result/bin:$PATH ./result/bin/devenv-run-tests --only dotenv tests

I get

error: string '.env' doesn't represent an absolute path