1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-10 21:29:48 +01:00

direnv: Apply nushell env transformations

In nushell, the ENV_CONVERSIONS environment variable is used to
transform the defined variables from a string to a nushell value (PATH
to a list being one of the most common uses). This commit applies
user-defined conversions to direnv-loaded variables.

This fixes binary autocompletion not being triggered for newly added
paths and makes direnv work consistently with nushell
This commit is contained in:
Joaquín Triñanes 2023-12-17 13:45:58 +01:00 committed by Mikilio
parent c48e350d72
commit 63d6e2de24
No known key found for this signature in database
GPG key ID: 5B2F1A890CF33F3F
2 changed files with 16 additions and 11 deletions

View file

@ -132,16 +132,21 @@ in {
# Using mkAfter to make it more likely to appear after other # Using mkAfter to make it more likely to appear after other
# manipulations of the prompt. # manipulations of the prompt.
mkAfter '' mkAfter ''
$env.config = ($env | default {} config).config $env.config = ($env.config? | default {})
$env.config = ($env.config | default {} hooks) $env.config.hooks = ($env.config.hooks? | default {})
$env.config = ($env.config | update hooks ($env.config.hooks | default [] pre_prompt)) $env.config.hooks.pre_prompt = ($env.config.hooks.pre_prompt? | default [] | append {||
$env.config = ($env.config | update hooks.pre_prompt ($env.config.hooks.pre_prompt | append { let direnv = (${cfg.package}/bin/direnv export json | from json | default {})
code: " if ($direnv | is-empty) {
let direnv = (${cfg.package}/bin/direnv export json | from json) return
let direnv = if not ($direnv | is-empty) { $direnv } else { {} } }
$direnv | load-env $direnv
" | items {|key, value|
})) {
key: $key
value: (do ($env.ENV_CONVERSIONS? | default {} | get -i $key | get -i from_string | default {|x| $x}) $value)
}
} | transpose -ird | load-env
})
''); '');
}; };
} }

View file

@ -14,6 +14,6 @@
in '' in ''
assertFileExists "${configFile}" assertFileExists "${configFile}"
assertFileRegex "${configFile}" \ assertFileRegex "${configFile}" \
'let direnv = (/nix/store/.*direnv.*/bin/direnv export json | from json)' 'let direnv = (/nix/store/.*direnv.*/bin/direnv export json \| from json | default {})'
''; '';
} }