Home manager setting in a system module fails with attribute missing

I want to set a home manager config in one system module (I don’t want to manage two separate files and include them in different places). But it fails with an error, that

The code for bar.nix:

{ config, pkgs, ... }: {
  imports = [
    # ...
  ];

  options = { };

  config = {
    home-manager.users.mobergmann = {
      xdg.configFile."foo".source =
        config.lib.mkOutOfStoreSymlink /home/mobergmann/nixos/configs/foo;
    };
  };
}

Is imported like so in default.nix

{ pkgs, ... }:

{
  imports = [
    # Include the results of the hardware scan.
    ./hardware-configuration.nix
    ../../modules/bar.nix
  ];

  # ...
}

fails with the error:

       error: attribute 'mkOutOfStoreSymlink' missing
       at /nix/store/fl33ji7l2sgy16mqakbyyz36m2j5amc9-source/modules/bar.nix:34:9:
           33|       xdg.configFile."foo".source =
           34|         config.lib.mkOutOfStoreSymlink /home/mobergmann/nixos/configs/foo;
             |         ^
           35|     };

I could not figure out why this error occurs. My guess is, that nix tries to use config not from home manager, but from the system, which doesn’t have lib.file.mkOutOfStoreSymlink. But I could not figure out how to solve this.

I hope some of you can help me.

   config = {
-    home-manager.users.mobergmann = {
+    home-manager.users.mobergmann = {config, ...}: {
       xdg.configFile."foo".source =
         config.lib.mkOutOfStoreSymlink /home/mobergmann/nixos/configs/foo;
     };
   };
1 Like

I still get the same error message: error: attribute ‘mkOutOfStoreSymlink’ missing

If you need more information, I would be happy to provide it. Just say so.

Because it’s in config.lib.file according to a quick web search.

1 Like

Well, that explains it. Somewhere I read, that config.lib.file.mkOutOfStoreSymlink was deprecated in favor for config.lib.mkOutOfStoreSymlink, but that was apparently wrong.
I am happy, thank you very much for helping :heart_hands:!