jakehamilton / config

One Nix flake to rule them all.
Other
360 stars 21 forks source link

Accessing plusultra options from within homemanager #20

Closed stratosgear closed 3 months ago

stratosgear commented 6 months ago

Hi again,

I know this is not a bug and this is not a support channel, but I have the following, seemingly easy question, that I cannot figure out on my own.

Assuming that I have activated a suite, like in:

plusultra.suites.development.enable = true; 

where I install some development tools.

If I would also like to set some aliases for some of the users defined in /homes/x86_64-linux/aUser@someHost only if the development suite has been enabled (as above) how would I query if the suite is enabled?

If I try:

  environment = mkIf config.plusutlra.suites.development.enable {
    interactiveShellInit = ''
     alias someAlias ='someCommand with some params'
    '';
  };

I get:

       error: attribute 'suites' missing                                                                                                                                                                          

       at /nix/store/fz9mqzjr2s7yd1y4b2ixakkpkr96zh5z-ah6f4r5ydx71ward72nv341v4hrcrra6-source/homes/x86_64-linux/someUser@someHost/default.nix:29:22:                                                               

           28|                                                                                                                                                                                                    
           29|   environment = mkIf config.plusultra.suites.development.enable {                                                                                                                                  
             |                      ^                                                                                                                                                                             
           30|     interactiveShellInit = ''   

How do I access the "namespace?" of where all the nixos modules are defined?

It's such a abstract concept that I do not have any keywords to help me google this out... :(

Thanks!

jakehamilton commented 6 months ago

Hey there! Home manager modules also get an osConfig argument that refers to the nixos (or Darwin) config. You should be able to reference that in order to set things dynamically.

So for example:

{ lib, osConfig ? {}, ... }:

{
  config = lib.mkIf (osConfig.plusultra.suites.something or false) {
    myOption = myValue;
  };
}
stratosgear commented 6 months ago

Great thanks, that works!!! I had seen the osConfig in the header but it never clicked to me what it meant :(

Now that I think about it, for symmetry reasons, does the reverse make sense? Accessing a home-manager setting from within the nixos config? How would that work?

jakehamilton commented 6 months ago

@stratosgear Yes! You can do the reverse by setting home-manager.users.${name}.*.

Heads up that if you're using Snowfall Lib, the next version won't work when using home-manager.users.${name}. Instead you can use snowfallorg.user.${name}.home.config.*.