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

Confused about Homes #21

Open
PlaneTraveller opened this issue Apr 1, 2024 · 9 comments
Open

Confused about Homes #21

PlaneTraveller opened this issue Apr 1, 2024 · 9 comments

Comments

@PlaneTraveller
Copy link

Hello Jake!

After reading all the issues related to homes, snowfall documentation, and experimenting a bunch, I'm still confused about whether or not to use Homes for my use cases (primarily use NixOS, but wouldn't mind the ability to "deploy" my entire home config to foreign distros like Arch).

This is more of a design question than a practical one. How is snowfall designed to handle home-manager/NixOS segregation? I noticed that most people just throw all their home configs into modules/nixos, but I couldn't help but feel that this is not the best practice. If, for example, I were forced to use some foreign distro (on a public server), I would have to redesign a separate config hierarchy using home-manager to be able to have my "home" on said server, which is probably not the design of snowfall. I would also love to be able to share my config with Nix non-believers without imposing my username and other personal data.

So what is the best practice for using snowfall with NixOS + separable Home? Should I put everything home-related under modules/home and not include home-manager at all in modules/nixos? Is it possible to do that?

As a Nix beginner, configuring stuff in modules/home seems super complex, with all the namespaces and referencing. Your config, (and IogaMaster's) are my guides, but yours have a home directory under both modules/home and modules/nixos. It seems that you are not really using Homes that much. At this point, using Homes kind of defeats the purpose of snowfall, which is to abstract away the wiring of configurations and provide a simple, elegant structure for them. My current solution is to put everything under nixos again and call it a day.

Is it that I completely misunderstood how snowfall is supposed to be used? It would be really helpful if you could explain how snowfall is designed to be used (in the future and right now).

Thank you so much for snowfall and your config! They made me think a lot about what Nix is capable of and configuring systems in general! These are both wonderful projects and I'm amazed by how you are able to pull it off (almost) alone. If I ever get good enough with Nix, I would love to contribute!

Sorry for using github issues completely wrong lol

@mainrs
Copy link

mainrs commented May 21, 2024

What I found a little bit confusing too is the fact that Jake is sometimes defining the same stuff twice: in nixos and in homes. An example would be direnv.

As far as your question goes: I think the separation is not optimal here. Jake doesn't use homes that much. My own configuration is inspired be this one too, but I moved way more into homes. Basically everything that is possible and that I do not consider a "system package": CLI tools I often put into homes. But packages that are more set in stone and require more system integration I put into nixos (steam for example).

There are some apps I am not certain about myself. firefox I have on every machine I run. The only use-case that I use standalone homes is to quickly pull in a development environment on machines that I might not own (think of cluster machines). So in those cases I don't require firefox for example.

@PlaneTraveller
Copy link
Author

Thank you for your advice! I started doing the same after a fair bit of exploring. I’m a bit stuck with how duplicate declarations of home and user interact which caused weird issues on my recently nixified laptop. Could you please share your config? I don’t mind at all if it’s not polished or anything. I just need some example of how someone else does it.

You can find my config here:
https://github.com/PlaneTraveller/Snowfall-experiment

@mainrs
Copy link

mainrs commented May 22, 2024

Thank you for your advice! I started doing the same after a fair bit of exploring. I’m a bit stuck with how duplicate declarations of home and user interact which caused weird issues on my recently nixified laptop. Could you please share your config? I don’t mind at all if it’s not polished or anything. I just need some example of how someone else does it.

You can find my config here: PlaneTraveller/Snowfall-experiment

Mine is available at https://github.com/mainrs/nixos.

What I found a little bit confusing was the fact that options reside inside the plusultra namespace. I think the reasoning for this is to allow nixos modules to access flags that are set inside homes modules. That way every option resides inside the same umbrella namespace.

I think I had to use this only once here to check if direnv is available inside my system:

https://github.com/mainrs/nixos/blob/d1b23f0ef358dcee42419097f78145439bf0b6ff/modules/nixos/nix/default.nix#L25-L50

@PlaneTraveller
Copy link
Author

Thank you for your advice! I started doing the same after a fair bit of exploring. I’m a bit stuck with how duplicate declarations of home and user interact which caused weird issues on my recently nixified laptop. Could you please share your config? I don’t mind at all if it’s not polished or anything. I just need some example of how someone else does it.
You can find my config here: PlaneTraveller/Snowfall-experiment

Mine is available at https://github.com/mainrs/nixos.

What I found a little bit confusing was the fact that options reside inside the plusultra namespace. I think the reasoning for this is to allow nixos modules to access flags that are set inside homes modules. That way every option resides inside the same umbrella namespace.

I think I had to use this only once here to check if direnv is available inside my system:

https://github.com/mainrs/nixos/blob/d1b23f0ef358dcee42419097f78145439bf0b6ff/modules/nixos/nix/default.nix#L25-L50

I think the purpose of putting all custom options under a namespace is to avoid conflicting with nixos options. At least that was why I switched to a custom namespace. For me, services.xxx often conflicts with NixOS options, so I just put them under a custom namespace to avoid the pain of renaming things.

Thanks for your config! I'll check it out

@jakehamilton
Copy link
Owner

@PlaneTraveller Hey there!

I originally started my configuration with only NixOS, no home-manager support. After a while I started to incorporate home-manager on the NixOS side and eventually wanted to use it on macOS as well. Because of this my config is still mostly NixOS. However, I am slowly moving things from NixOS to be managed by home-manager where possible. Some things need OS-level configuration as well and for that I keep them in the NixOS and nix-darwin modules.

My advice for someone starting out right now is to prefer home-manager modules where possible due to their portability. For how to do that with Snowfall Lib, you can add modules to your modules/home directory which can then be configured via your individual homes in homes/. You don't need to do the same thing I do with a NixOS module for proxying to home-manager, that feature is now included in Snowfall Lib via the NixOS options at snowfallorg.users.<name>.home.config. Though that's only available on the dev branch and isn't really documented just yet (working on that today).

@mainrs
Copy link

mainrs commented May 22, 2024

You don't need to do the same thing I do with a NixOS module for proxying to home-manager, that feature is now included in Snowfall Lib via the NixOS options at snowfallorg.users.<name>.home.config. Though that's only available on the dev branch and isn't really documented just yet (working on that today).

Ohh, good to know! I really liked your approach. There are some applications that I consider to be system-level but that are declarable via home-manager. That's why I adopted that approach, too!

@bestlem
Copy link

bestlem commented May 23, 2024

One of the confusions I have here about duplicate definitions is where user is set and used.
In @jakehamilton config there is a user ( options.plusultra.user) in all of modules/home and modules/darwin and modules/nixos.

There is also the 3 definitions in the snowfallorg library.

How do all these definitions interact?

Surely user should be defined in just one place. At least for things like Full name and email.

@mainrs
Copy link

mainrs commented May 29, 2024

You don't need to do the same thing I do with a NixOS module for proxying to home-manager, that feature is now included in Snowfall Lib via the NixOS options at snowfallorg.users.<name>.home.config. Though that's only available on the dev branch and isn't really documented just yet (working on that today).

Could you give me a small example on how this would work on the dev branch? Currently this looks like this in my config (same as yours):

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

with lib;
with lib.zt;

let cfg = config.zt.apps.firefox;
in {
  options.zt.apps.firefox = with types; {
    enable = mkBoolOpt false "Whether or not to enable Firefox.";
  };

  config = mkIf cfg.enable {
    # Install inside home-manager.
    zt.home.extraOptions = {
      programs.firefox = {
        enable = true;
        package = pkgs.firefox.override {
          cfg = { enableGnomeExtensions = config.zt.desktop.gnome.enable; };
        };

        # NOTE: Firefox extensions installed via Mozilla Firefox account.
      };

    };

    # Make sure to enable browser connectors in case we have a matching desktop environment enabled.
    services.gnome.gnome-browser-connector.enable =
      config.zt.desktop.gnome.enable;
  };
}

It seems to still make sense to abstract once over snowfallorg.users.<name>.home.config, since I need the username to access the property.

@rbangert
Copy link

Here is an example of how I'm using it on v3.0.3.

modules/home/desktop/rofi/default.nix

{ lib, config, pkgs, namespace, ... }:
with lib;
with lib.${namespace};
let cfg = config.${namespace}.desktop.rofi;
in {
  options.${namespace}.desktop.rofi = { enable = mkEnableOption "rofi"; };

  config = mkIf cfg.enable {
    home = {
      packages = with pkgs; [ rofi-wayland ];

      file.".config/rofi" = {
        source = ../../../../config/rofi;
        recursive = true;
      };
    };
  };
}

homes/<user>@<host>/default.nix

{ lib, pkgs, namespace, ... }:
with lib.${namespace}; {
  rr-sv = {
    desktop = {
      rofi = enabled;
    };
  };
}

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

5 participants