You could probably use shellHook and the git config command (by default it sets configuration for the current repository, which is different from global config). That seems a bit hacky to me though, I’d personally just manually set those options on the repository.
Not directly an answer to your question, though I have a similar problem and collect all my work related stuff in a separate base folder, I then configured git to use a different configuration when in that folder.
This way I do not have to remember setting it up correctly in the shell each time.
The Home-Manager style to configure that, looks like this:
Would it be possible to modify the Git’s Nix expression to make it customizable in a shell.nix, similar to how it can be done with Vim? As far as I know, Git is configured with an rc file and environment variables, just as Vim.
Have nothing against the accepted answer, but it would be nice to transfer my NixOS config (almost) verbatim to a shell.nix as I did with Vim.
Stackoverflow isn’t a reference manual, I really recommend looking at the actual documentation for things like this. Jokes about git man pages aside, high level stuff like this is nicely documented in man git.
If a path is provided to GIT_CONFIG_GLOBAL, then it will be copied to the Nix store (no writeText needed)
For example:
GIT_CONFIG_GLOBAL = ./config_files/git.conf
writeText (and co.) becomes a derivation (i.e., a .drv file in the Nix store) so how can it be assigned to a shell variable as if it was the end result?
nix-repl> pkgs.writeText "lofa" ''
falho
vert
lofa
''
«derivation /nix/store/572zrrh4jg2qimw8xfcjjnf75jkv0syp-lofa.drv»
I remember something about this in one of the manuals (that “intermediate” derivation will get instantiated or something), but can’t remember in which (and where)…
Why does GIT_CONFIG_GLOBAL work outside of shellHook?
I don’t think this is documented (see thread), but
variables in mkShell but outsideshellHook will become ENVIRONMENT VARIABLES
variables inside shellHook become SHELL VARIABLES (unless explicitly exported)