snowfallorg / snowfallorg/lib

Infinite recursion when using namespace in home configuration

Open
#142 9 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Nix
Stars
628
Forks
64
PR merge metrics
No merged PRs in 30d

Description

Hello.

I am trying to build a simple flake with snowfall, but when I try to use a namespaced module in my home configuration, I get the following error:

building the system configuration...
error:
       … while calling the 'head' builtin
         at /nix/store/4r8s42c9mwfvgdlxv0izb1cmlzrsb5nz-source/lib/attrsets.nix:1574:11:
         1573|         || pred here (elemAt values 1) (head values) then
         1574|           head values
             |           ^
         1575|         else

       … while evaluating the attribute 'value'
         at /nix/store/4r8s42c9mwfvgdlxv0izb1cmlzrsb5nz-source/lib/modules.nix:816:9:
          815|     in warnDeprecation opt //
          816|       { value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          817|         inherit (res.defsFinal') highestPrio;

       … while evaluating the option `system.build.toplevel':

       … while evaluating definitions from `/nix/store/4r8s42c9mwfvgdlxv0izb1cmlzrsb5nz-source/nixos/modules/system/activation/top-level.nix':

       … while evaluating the option `assertions':

       … while evaluating definitions from `/nix/store/q1ss75nhmjiydyqw8lbzwbx7cqk8z0qq-source/nixos/common.nix':

       … while evaluating the module argument `namespace' in "/nix/store/9bwi858z3pzcgf9g40bwqvr52lz2zycd-s6wc8mk3jb8ja70aawm5s0ndmda1cyvh-source/homes/x86_64-linux/bear@nixos-laptop/default.nix":

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: infinite recursion encountered
       at /nix/store/4r8s42c9mwfvgdlxv0izb1cmlzrsb5nz-source/lib/modules.nix:515:28:
          514|         addErrorContext (context name)
          515|           (args.${name} or config._module.args.${name})
             |                            ^
          516|       ) (functionArgs f);

I am fairly surprised this is happening since the flake is as small as it can get. Just a module, a home configuration file and a system configuration file; here's their contents:

# modules/home/foo/default.nix
{ namespace, lib, ... }:
with lib;
{
    options."${namespace}".foo = {
        enable = mkEnableOption "Foo";
    };
}
# homes/x86_64-linux/bear@nixos-laptop
{ pkgs, lib, namespace, ... }:
{
    "${namespace}".foo.enable = true;
    home.stateVersion = "24.05";
}
# systems/x86_64-linux/nixos-laptop
{ config, namespace, lib, pkgs, ... }:
{
    imports = [./hardware.nix];

    users.users."bear" = {
        isNormalUser = true;
    };

    system.stateVersion = "24.05";
}
# flake.nix
{
    description = "DataMarket's NixOS flake";

    inputs = {
        # Nix Packages
        nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

        # Snowfall
        snowfall-lib = {
            url = "github:snowfallorg/lib";
            inputs.nixpkgs.follows = "nixpkgs";
        };

        # Home Manager
        home-manager = {
            url = "github:nix-community/home-manager/release-24.05";
            inputs.nixpkgs.follows = "nixpkgs";
        };
    };

    outputs = inputs: inputs.snowfall-lib.mkFlake {
        inherit inputs;
        src = ./.;

        channels-config = {
            allowUnfree = true;
        };
    };
};

If i change "${namespace}" to a hardcoded internal in the line the module is enabled, it works.

Thanks in advance.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the namespace argument evaluation shown in the error, then compare modules/home/foo/default.nix with homes/x86_64-linux/bear@nixos-laptop and the flake.nix configuration. Reproduce the minimal flake build and determine why using "${namespace}" recurses while hardcoding internal works; done means the namespaced home module evaluates without infinite recursion.

Written by the indexing model from the issue text.

Assessment

Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.