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 external modules from flakes #106

Closed
diogox opened this issue Jan 31, 2021 · 8 comments
Closed

Home-manager external modules from flakes #106

diogox opened this issue Jan 31, 2021 · 8 comments
Labels
enhancement New feature or request

Comments

@diogox
Copy link
Contributor

diogox commented Jan 31, 2021

I was wondering if there is a way to allow adding home-manager modules like we add other external modules in the flake.nix file.

The use case I'm trying to solve is adding nix-doom-emacs's module to my user.

The workaround I currently have in place is to define:

externModules = [
  home.nixosModules.home-manager
  {
  # The workaround:
    home-manager.users.diogox = { pkgs, ... }: {
      imports = [ nix-doom-emacs.hmModule ];
    };
  }
];

Where I import the HM module for my user.

But this defines my username in the flake.nix file, which is not ideal.

Can you see any way to, I guess, either provide a mechanism that will import the HM modules for all users, or provide inputs to the user nix files, so that they can be imported there, like in the example above?

@nrdxp
Copy link
Collaborator

nrdxp commented Feb 1, 2021

you could try using builtins.getFlake inside your user profile as a better workaround. We could probably solve this by adding another specialArg to all modules.

@diogox
Copy link
Contributor Author

diogox commented Feb 2, 2021

I followed your builtins.getFlake advice. It's a better workaround.

Only downside is that I need to specify the commit hash I want to fetch (as far as I can tell).

Which makes it harder to update. But it's not a big deal.

Thanks 🙌

@Pacman99
Copy link
Member

Pacman99 commented Feb 4, 2021

I was just looking at the core branch and thought about this, it would be good if extern has a specialArgs attribute. It would also be useful for mobile-nixos usage, which will be getting flakes support soon.

@nrdxp nrdxp mentioned this issue Feb 15, 2021
17 tasks
@nrdxp nrdxp added the enhancement New feature or request label Feb 17, 2021
@nrdxp nrdxp closed this as completed in 92a69cb Feb 20, 2021
@nrdxp
Copy link
Collaborator

nrdxp commented Feb 20, 2021

Just inherit the modules into the empty attribute set...

@figgyc
Copy link

figgyc commented Feb 21, 2021

Hi, is there a good example on the proper usage? I'm trying to import nix-doom-emacs as described in the docs but I'm having some issues.

extern/default.nix:

{ inputs }: with inputs;
let
  hmModules = {
    inherit (nix-doom-emacs.hmModule) hmModule; # I've tried without .hmModule to the same effect
  };
in
{
  modules = [
    home.nixosModules.home-manager
    ci-agent.nixosModules.agent-profile
  ];

  overlays = [
    nur.overlay
    devshell.overlay
    emacs.overlay
    (final: prev: {
      deploy-rs = deploy.packages.${prev.system}.deploy-rs;
    })
  ];

  # passed to all nixos modules
  specialArgs = {
    inherit hmModules; # sidenote - I think this needs changing as it's "hm-modules" still in the current core branch
    overrideModulesPath = "${override}/nixos/modules";
    hardware = nixos-hardware.nixosModules;
  };
}

users/profiles/emacs/default.nix:

{ config, lib, pkgs, hmModules, ... }:

{
  imports = [ hmModules.hmModule ];
  programs.doom-emacs = {
    enable = true;
    package = pkgs.emacsPgtkGcc;
    doomPrivateDir = ./doom.d;
  };

  services.emacs = {
    enable = true;
    #package = programs.doom-emacs.package;
  };

}

The error I get:

$ flk home e7240 figgyc switch --show-trace
error: --- EvalError ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- nix
at: (303:28) in file: /nix/store/pz44872rmpd7ygqfmdcwh4ac6hk1hy4s-source/lib/modules.nix

   302|         value = builtins.addErrorContext (context name)
   303|           (args.${name} or config._module.args.${name});
      |                            ^
   304|       }) requiredArgs);

infinite recursion encountered
(use '--show-trace' to show detailed location information)

@Pacman99
Copy link
Member

for one thing, specialArgs only affects the nixos configurations and not home-manager. So you would have to do the import in your user profile:

{ hm-modules, ... }:
{ home-manager.users.me.imports = hm-modules; }

Then you can use the modulle in any user profile.

But I have no idea how you got an infinite recursion error, I would have thought the error would be from the file not being called with hmModule.

@nrdxp
Copy link
Collaborator

nrdxp commented Feb 21, 2021

I fixed the typo in lastest core, also put a bit of documentation up last night, I'll expand with this example later. But for now, get it working. Also made it available by default from the community branch.

@figgyc
Copy link

figgyc commented Feb 21, 2021

Yeah that works perfectly. Thanks!

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

No branches or pull requests

4 participants