In trying to convert this concept to an optional module that provides a default list of ruby versions that can be overridden, I’m getting stuck with an infinite recursion. (See below).
Any help — much appreciated!
So the home-manager module that I’m trying to build which (if enabled) allows to generate the relevant list of ruby versions into ~/.rubies is as follows in its current incarnation and the error is captured here: https://pastebin.com/0LcuCrai:
{ pkgs, lib, config, ... }:
with lib;
with attrsets;
let
cfg = config.programs.ruby;
mkRubyAttrSet = dir: list:
let
mkName = r: "${dir}/ruby-${r.version}";
mkSetsList = map (r: nameValuePair (mkName r) r) list;
in
listToAttrs (mkSetsList);
in
{
options = {
programs.ruby = {
enable = mkEnableOption "A pseudo ruby-install module.";
packages = mkOption {
type = types.listOf types.package;
default = with pkgs; [
ruby_2_7
ruby_3_0
ruby_3_1
];
example = [ pkgs.ruby_3_0 pkgs.ruby_3_1 ];
description = "The set of ruby packages to appear in the user environment.";
};
path = mkOption {
type = types.str;
default = ".rubies";
description = "The user directory to install the rubies into.";
};
};
};
config = mkIf cfg.enable {
home = mapAttrs (name: r: {
file."${name}" = {
source = r;
target = name;
};
}) (mkRubyAttrSet cfg.path cfg.packages);
};
}
Perhaps there’s a much simpler syntax? Anyway, I’ve tried lots of variations (as posted on the #home-manager topic on discord). So if anyone is able to get me out of the wilderness on this one, that’d be awesome! Thanks!
Well this is weird… infinite recursion using a default value. Help!
...
options = {
programs.ruby = {
enable = mkEnableOption "A pseudo ruby-install module.";
packages = mkOption {
type = types.listOf types.package;
default = defaultRubies;
description = "The set of ruby packages to appear in the user environment.";
};
path = mkOption {
type = types.str;
default = ".rubies";
description = "The user directory to install the rubies into.";
};
};
};
...
So I thought I could avoid the infinite recursion by defining a default list of strings — the names of the packages to be installed. But, sadly this also fails with an infinite recursion .
I was hoping that additional ones could be registered via overlaying the pkgs — which is less convenient than the original design of just overriding the optional list, but getting something working at this stage is preferable.