Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Home-Manager Just don't work. #156

Open
Jetiaime opened this issue Jan 15, 2025 · 4 comments
Open

Home-Manager Just don't work. #156

Jetiaime opened this issue Jan 15, 2025 · 4 comments

Comments

@Jetiaime
Copy link

I a new guy for Nix and Snowfall, they are very awesome by the way. But I got a little trouble for configuring my nix-darwin configuration. There is my nix-configuration repository, how can I trigger the home-manager configuration on my MacOS? Please help.

And I got another confuse thing —— if I have a module that only works on dawin (like raycast for example), or only works on linux, and I wanna put it in my home-manager, where can I put it in? Maybe we should split the module/homes to two part like: modules/homes/linux and modules/homes/darwin, just like modules itself. What do you think? Thank you for your great job again!

@jameslounds
Copy link

jameslounds commented Jan 16, 2025

Looks like your home configuration has some issues, but nix error messages can be really hard to read, or just entirely unhelpful.

Here are the things I noticed:

  • namespaces aren't passed to homes, so you need to manually specify teamo for the namespace in homes/aarch64-darwin/teamo@blaze/default.nix this is a bug and should be fixed soon Infinite recursion when using namespace in home configuration #142
  • lib.${namespace}.mkBoolOption is used but not defined. I think you mean lib.mkEnableOption here.
  • lib.snowfall.systems.isDarwin is a typo. The correct function is lib.snowfall.system.is-darwin

@Jetiaime
Copy link
Author

Looks like your home configuration has some issues, but nix error messages can be really hard to read, or just entirely unhelpful.

Here are the things I noticed:

* namespaces aren't passed to `homes`, so you need to manually specify `teamo` for the namespace in `homes/aarch64-darwin/teamo@blaze/default.nix` this is a bug and should be fixed soon  [Infinite recursion when using namespace in home configuration #142](https://github.com/snowfallorg/lib/issues/142)

* `lib.${namespace}.mkBoolOption` is used but not defined. I think you mean `lib.mkEnableOption` here.

* `lib.snowfall.systems.isDarwin` is a typo. The correct function is `lib.snowfall.system.is-darwin`

Thank you for your response! I reviewed my code and found the same issue. I’ve managed to fix most of the problematic code, and everything else works fine now—except for the Obsidian module. This has been quite frustrating.

That said, I plan to follow the community's advice and learn how to create a package. I’ll also work on migrating my Homebrew casks to Nixpkgs. Thanks again !

@Jetiaime
Copy link
Author

I’ve updated my Nix configuration repository here, but I’m still encountering an issue:

homes/aarch64-darwin/teamo@blaze/default.nix:

{
  lib,
  namespace,
  ...
}: let
  inherit (lib.${namespace}) enabled;
in {
  teamo = {
    # I don't know why it doesn't work.
    # home = {
    #   enable = true;
    #   stateVersion = "24.11";
    # };
    # user = {
    #   enable = true;
    #   email = "[email protected]";
    # };

... exiting code ...

  # It should be stay in `home/default.nix`, but it doesn't work, so I have to put it here.
  programs.home-manager = enabled;
  home.stateVersion = "24.11";
}

modules/home/home/deafult.nix:

{
  lib,
  config,
  namespace,
  ...
}: let
  inherit (lib) mkIf;
  inherit (lib.${namespace}) mkStrOpt mkBoolOpt enabled;

  cfg = config.${namespace}.home;
in {
  options.${namespace}.home = {
    enable = mkBoolOpt false "Whether or not enable home configuration.";
    stateVersion = mkStrOpt "" "The state version of the home configuration.";
  };

  config = mkIf cfg.enable {
    programs.home-manager = enabled;
    home.stateVersion = cfg.stateVersion;
  };
}

modules/home/user/default.nix:

{
  lib,
  config,
  system,
  namespace,
  ...
}: let
  inherit (lib) mkIf;
  inherit (lib.${namespace}) mkStrOpt mkBoolOpt;
  inherit (lib.snowfall.systems) isDarwin;

  cfg = config.${namespace}.user;
in {
  options.${namespace}.user = {
    enable = mkBoolOpt false "Whether or not enable user configuration.";
    name =  mkStrOpt config.snowfall.user.name "The name of the user.";
    email = mkStrOpt "" "The email address of the user.";
    home = mkStrOpt (
      if isDarwin system
      then "/Users/${cfg.name}"
      else "/home/${cfg.name}"
    ) "The home directory of the user.";
  };

  config = mkIf cfg.enable {
    home = {
      username = cfg.name;
      homeDirectory = cfg.home;
    };
  };
}

Could you help me understand why the code above doesn’t work? I’d greatly appreciate your guidance.

@Jetiaime
Copy link
Author

Jetiaime commented Jan 17, 2025

I think I’ve identified the problem. If I modify the file without adding it to the Git stage, the build will succeed initially but later result in an error like this:

warning: Git tree '/Users/teamo/.config/nix-darwin' is dirty
error:
       … while evaluating the attribute 'value'
         at /nix/store/awsvw44jla0idziiks2zwgzslfd2dczn-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':

       … while evaluating the attribute 'mergedValue'
         at /nix/store/awsvw44jla0idziiks2zwgzslfd2dczn-source/lib/modules.nix:851:5:
          850|     # Type-check the remaining definitions, and merge them. Or throw if no definitions.
          851|     mergedValue =
             |     ^
          852|       if isDefined then

       … while evaluating definitions from `/nix/store/wy0a6vicf8c9hhnq92p4y58ph06i6ivm-source/modules/environment':

       … while evaluating the option `environment.systemPath':

       … while evaluating definitions from `/nix/store/wy0a6vicf8c9hhnq92p4y58ph06i6ivm-source/modules/environment':

       … while evaluating the option `environment.profiles':

       … while evaluating definitions from `/nix/store/wy0a6vicf8c9hhnq92p4y58ph06i6ivm-source/modules/users':

       … while evaluating the option `users.users.teamo.packages':

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

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

       error: The option `home-manager.users.teamo.teamo.programs.gui.browser' does not exist. Definition values:
       - In `/nix/store/wjhgbvxma3cgqpldmclpk68gz0rrasfs-f0r660mhyj4g66qk186jbm1nnmyrr4sj-source/homes/aarch64-darwin/teamo@blaze/default.nix':
           {
             chrome = {
               enable = true;
             };
           }

it's easily to reproduction, you should just make a bran new home-manager module, like this:

modules/home/programs/gui/browser/chrome/default.nix

{
  lib,
  pkgs,
  config,
  namespace,
  ...
}: let
  inherit (lib) mkIf;
  inherit (lib.${namespace}) mkBoolOpt;

  cfg = config.${namespace}.programs.gui.browser.chrome;
in {
  options.${namespace}.programs.gui.browser.chrome = {
    enable = mkBoolOpt false "Whether or not enable chrome.";
  };

  config = mkIf cfg.enable {
    home.packages = with pkgs; [
      google-chrome
    ];
  };
}

And then enable the configuration on the homes/<user>@<host>/default.nix like:

{
  lib,
  namespace,
  ...
}: let
  inherit (lib.${namespace}) enabled;
in {
    ... other code ...

    programs = {
      gui = {
        browser = {
          chrome = enabled;
        };
      };
    };

   ... other code ...
  };
}

If you skip adding those files to Git and proceed with the build, like this:

Image

You’ll encounter the same error mentioned above. And if you add it into Git stage, it will build successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants