Dear Nix community,
I can’t get the following expression working to add a list of additionalJDKs
packages to my home directory via NixOS-module home-manager:
proglangs.nix
:
{ pkgs, ... }:
let
additionalJDKs = with pkgs; [ temurin-bin-11 temurin-bin-17 ];
in
{
# ...
programs.java = { /*...*/ };
home.sessionPath = [ "$HOME/.jdks" ];
} //
(builtins.listToAttrs (builtins.map (jdk: { name = home.file.".jdks/${jdk.version}".source; value = jdk; }) additionalJDKs))
The problem with this script is, that the home
-variable isn’t found (what I’m not really getting - the scope should be the same as the “main” set…)
error:
… while calling the 'head' builtin
at /nix/store/80v3x99d9cl7h9fbhqrpajwg4vjyxg6y-source/lib/attrsets.nix:922:11:
921| || pred here (elemAt values 1) (head values) then
922| head values
| ^
923| else
… while evaluating the attribute 'value'
at /nix/store/80v3x99d9cl7h9fbhqrpajwg4vjyxg6y-source/lib/modules.nix:807:9:
806| in warnDeprecation opt //
807| { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
| ^
808| inherit (res.defsFinal') highestPrio;
(stack trace truncated; use '--show-trace' to show the full trace)
error: undefined variable 'home'
at /nix/store/byh8bclwsdlx5awqr35jk2mwpfdzimvc-source/home-manager/devel/proglangs.nix:83:53:
82| } //
83| ( builtins.listToAttrs (builtins.map ( jdk: {name = home.file.".jdk/${jdk.version}".source; value = jdk; }) additionalJDKs))
| ^
84|
Link to referenced file
A messy workaround I’m currently using to archive the wanted behavior by neglecting length-dynamic evaluation:
{ pkgs, ... }:
let
additionalJDKs = with pkgs; [ temurin-bin-11 temurin-bin-17 ];
in
{
# ...
programs.java = { /*...*/ };
home.sessionPath = [ "$HOME/.jdks" ];
home.file.".jdks/${(builtins.elemAt additionalJDKs 0).version}".source = (builtins.elemAt additionalJDKs 0);
home.file.".jdks/${(builtins.elemAt additionalJDKs 1).version}".source = (builtins.elemAt additionalJDKs 1);
}
Related to: Fix collision with multiple JDKs - #2 by moaxcp