Can't access osConfig

Hi,

I’ve been trying to use osConfig in my home-manager to determine which version of LibreOffice to install:

# apps/libreoffice.nix
{ lib, pkgs, osConfig, ... }:

{
  home.packages = with pkgs; [
    hunspellDicts.en-gb-ize
  ] ++ (if (osConfig.services.xserver.desktopManager.plasma5.enable == true)
          then
            [libreoffice-qt]
          else
            [libreoffice]
      );
}

I import this file in my home.nix

# home.nix
{ config, pkgs, ... }:

{
  programs.home-manager.enable = true;

  imports = [
    # .....
    ../apps/libreoffice.nix
  ];

However, I’m getting the error that attribute 'osConfig' missing. How can I access it correctly?

If this helps, here’s my entire configuration (without the libreOffice part, which hasn’t been pushed yet): GitHub - bratfizyk/dotFiles: My config files

osConfig is only available when using home-manager through the NixOS/nix-darwin modules. If you’re using home-manager standalone, it doesn’t have access to the OS config because it’s not being evaluated as part of building an OS configuration.

2 Likes

Thanks for the response. I think I understand the problem, but need help with one more thing.
Currently I use flakes for my system configuration and - you’re right - home-manager is not a system module.

(For clarity I skipped some lines in the snippet below)

      nixosConfigurations = {
        beko-nixos = lib.nixosSystem {
          inherit system;
          inherit pkgs;
          modules = [ 
            nixos-hardware.nixosModules.lenovo-legion-16achg6-hybrid
            ./legion/configuration.nix
          ];
        };
      };
      homeConfigurations = {
        beko = home-manager.lib.homeManagerConfiguration {
          inherit pkgs;
          modules = [
            nixvim.homeManagerModules.nixvim
            nur.nixosModules.nur
            ./legion/home.nix
          ];
        };
      };

I changed it so that it looks like this:

    nixosConfigurations = {
        beko-nixos = lib.nixosSystem {
          inherit system;
          inherit pkgs;
          modules = [ 
            nixos-hardware.nixosModules.lenovo-legion-16achg6-hybrid
            ./legion/configuration.nix

            home-manager.nixosModules.home-manager
            {
              home-manager.useGlobalPkgs = true;
              home-manager.useUserPackages = true;
              home-manager.users.beko = import ./legion/home.nix;
            }
            #nixvim.homeManagerModules.nixvim
            #nur.nixosModules.nur
          ];
        };
      };

Which in my understanding should solve the problem, but now I don’t know how to inject nixvim.homeManagerModules.nixvim and nur.nixosModules.nur modules into home-manager. When I naively uncomment them, I get an error saying “module home not defined”.

you should be able to put them in imports

    nixosConfigurations = {
        beko-nixos = lib.nixosSystem {
          inherit system;
          inherit pkgs;
          modules = [ 
            nixos-hardware.nixosModules.lenovo-legion-16achg6-hybrid
            ./legion/configuration.nix

            home-manager.nixosModules.home-manager
            {
              home-manager.useGlobalPkgs = true;
              home-manager.useUserPackages = true;
              home-manager.users.beko = {
                  imports = [
                      nixvim.homeManagerModules.nixvim
                      nur.nixosModules.nur
                      ./legion/home.nix;
                  ];
              };
            }
          ];
        };
      };
1 Like

It works! Thanks a lot.
I’ve updated my GH repo with config files.