can't request `user` inside an aspect's `nixos` class module
I was creating an aspect for Cosmic DE and realized I needed the user's name to enable autologin. I knew we could request either host, user, or both, so I requested user, but the nixos class module was skipped. I had this:
{
den.aspects.desktop.cosmic = {
nixos = { user, config, ... }: {
# entirely block is skipped
};
};
}
I checked the class modules page in the docs, but I didn't see any examples of the nixos class module requesting only user. I did, however, see examples adding host as well, so I tried doing the same:
{
den.aspects.desktop.cosmic = {
nixos = { host, user, config, ... }: {
# still skipped
};
};
}
No success. The only way to get something similar to the above working was to request user at the aspect level, like shown in the parametric page in the docs:
{
den.aspects.desktop.cosmic = { user, ... }: {
nixos = { config, lib, ... }: {
# No longer skipped.
services.displayManager.cosmic-greeter.enable = true;
services.desktopManager.cosmic.enable = true;
services.displayManager.autoLogin = {
enable = true;
user = user.userName;
};
};
};
}
For context, I am on NixOS, and this particular aspect doesn't have a homeManager class module. I also have options inside the nixosmodule, so it was easy to realize the entire module was being skipped because my options didn't register. The options were also the reason why I couldn't use provides.to-users = { user, ... } since it's outside the nixos class module and thus wouldn't have access to its config.
I'm not sure if this is a bug or me understanding parametric aspects wrong. The docs made it seem as if nixos = { host, user, ... } would work as long as we were in a context where host is present, which I am. I also assume user is always present because it seems we can request it from both system and home class modules, and because we can't really have a system without an user, but do correct me if I'm wrong on how Den approaches that.
I'll see if I can reproduce this scenario as a unit test -- can you confirm if there is in fact a user resolving on the particular host you're seeing this on? (Because obviously no user then no parametric expansion explaining the behavior.) And confirm that this aspect is indeed in the aspect tree?
I'm nearing delivery on den-hoag (probably early next week) which should also ship with much improved visualization/debugging tooling -- but I'll also be fixing any bugs in this branch and maintaining the den-fx (nix-effects) pipeline as a branch for a while to come.
can you confirm if there is in fact a user resolving on the particular host you're seeing this on? (Because obviously no user then no parametric expansion explaining the behavior.) And confirm that this aspect is indeed in the aspect tree?
I think so. I'm logged-in as my user on a desktop. The parametric expansion didn't work for the nixos class module, but it did work when I made the entire aspect parametric, so it is resolving a user. As for whether the aspect is in the aspect tree, if by that you mean whether I've included the aspect in my host/user or not, then yes I did.
I just tried again - same issue. I'm going to paste a simplified version of the module, my host config, and my Den config, but you're welcome to check out my (WIP) configuration at lucasshiva/nixconfig.
# modules/features/desktop/cosmic.nix
{
den.aspects.desktop.cosmic =
# Requesting `user` on the `nixos` class module isn't working. Maybe on purpose.
# For more information, see my issue at https://github.com/denful/den/issues/629
{ user, ... }:
{
nixos =
{
# requesting `user` here isn't working, so we make the whole aspect parametric.
# user,
config,
lib,
...
}:
let
cfg = config.my.cosmic;
in
{
options.my.cosmic = {
autoLogin = lib.mkOption {
type = lib.types.bool;
description = "Whether to enable auto login for Cosmic Greeter.";
example = true;
default = false;
};
};
config = {
# Enable the COSMIC login manager
services.displayManager.cosmic-greeter.enable = true;
# Enable the COSMIC desktop environment
services.desktopManager.cosmic.enable = true;
# Maybe we could move this to a more generic module, included in all desktop environments.
services.displayManager.autoLogin = lib.mkIf cfg.autoLogin {
enable = true;
user = user.userName;
};
};
};
};
}
You can see that I'm using options/config in this module. We've talked about your custom settings type before, but I ended up just using custom home/system modules instead, mostly because I can now create options that expect a package instead of a string, but also because it's closer to what I already had when I was not using Den.
Anyway, here's my host config:
# modules/hosts/void/void.nix
{ den, ... }:
let
hostname = "void";
username = "lucas";
in
{
den.hosts.x86_64-linux."${hostname}" = {
users."${username}" = { };
};
den.aspects."${hostname}" = {
includes = with den; [
aspects."${hostname}".hardware # Hardware config for this host.
aspects.hardware.gpu.nvidia
aspects.hardware.cpu.amd
aspects.hardware.pc.ssd
aspects.core.fonts
aspects.swap.zram
aspects.sound.pipewire
aspects.boot.systemd-boot
aspects.desktop.cosmic
aspects.apps.terminals.kitty
];
homeManager =
{ pkgs, config, ... }:
{
# Using a package (or config) would not be supported if we were to use the custom
# settingsType and provide settings via `den.hosts` instead.
my.kitty.shell = config.programs.fish.package;
home.packages = with pkgs; [
neovim
keepassxc
obsidian
];
};
nixos =
{ ... }:
{
# With the parametric `nixos` module, we get the following error:
# "The option `my.cosmic' does not exist."
my.cosmic.autoLogin = true;
};
};
}
As for Den-specific config, I only messed around with the defaults:
# modules/den/defaults.nix
{ den, ... }:
let
stateVersion = "26.05";
in
{
den.default.homeManager = {
home.stateVersion = stateVersion;
};
den.default.nixos = {
system.stateVersion = stateVersion;
# Allow unfree packages.
# Enable flakes.
# Enable networking.
# Locale settings
# Configure home-manager.
};
den.default.includes = with den; [
batteries.define-user
batteries.hostname
policies.host-guards # custom policy
aspects.nix.nh
];
}
You can see that I do have a custom policy, but I've already tried removing it to see if that was the problem. As for my user, I'm only including den.batteries.primary-user and den.batteries.host-aspects. Everything else is normal home-manager configuration. I don't think I'm doing anything too crazy on my config, so it's probably a bug somewhere.
By the way, does Den come with some sort of debug option? I'd love to get messages in the console due to some attribute failing to resolve in a parametric aspect or a class module instead of silently skipping.
By the way, does Den come with some sort of debug option? I'd love to get messages in the console due to some attribute failing to resolve in a parametric aspect or a class module instead of silently skipping.
It was proposed but rejected as there wasn't a pure way to enable it -- I manually add tracing when I need to debug. The den-hoag rewrite will have interactive graph utilities that should allow you to explore the evaluations and identify issues.
Sorry for the delay in looking into this report, going to try and reproduce it now.
#634 should fix it
Feel free to re-open if this didn't resolve your issue.