Sharing a home-manager config between NixOS and non-NixOS systems

Hello, this is my first time asking a question so I hope I’ve provided the right information!

I have number of systems; some are NixOS, some are not. I want to control both with the same home-manager config, from same flake.

I expected something like this to work:

let
    home = home-manager.lib.homeManagerConfiguration {
      pkgs = nixpkgs.legacyPackages.x86_64-linux;
      modules = [ ./home/bates64/home.nix ];
    };
in {
    homeConfigurations = {
      bates64 = home;
    };
    nixosConfigurations = {
      saturn = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          home-manager.nixosModules.home-manager
          {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.bates64 = home;
          }
        ];
      };
    };
  };
}

But I get this error:

error:
       … while calling the 'head' builtin
         at /nix/store/b0b72hll1hv73xdcjavqd94ibrs1knfc-source/lib/attrsets.nix:1574:11:
         1573|         || pred here (elemAt values 1) (head values) then
         1574|           head values
             |           ^
         1575|         else

       … while evaluating the attribute 'value'
         at /nix/store/b0b72hll1hv73xdcjavqd94ibrs1knfc-source/lib/modules.nix:816:9:
          815|     in warnDeprecation opt //
          816|       { value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          817|         inherit (res.defsFinal') highestPrio;

       … while evaluating the option `system.build.toplevel':

       … while evaluating definitions from `/nix/store/b0b72hll1hv73xdcjavqd94ibrs1knfc-source/nixos/modules/system/activation/top-level.nix':

       … while evaluating the option `assertions':

       … while evaluating definitions from `/nix/store/rffzp7ya96cg0ylw4q4lb65pxa8sydkk-source/nixos/common.nix':

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: Module `:anon-5:anon-1' has an unsupported attribute `activation-script'. This is caused by introducing a top-level `config' or `options' attribute. Add configuration attributes immediately on the top level instead, or move all of them (namely: activation-script activationPackage extendModules newsDisplay newsEntries pkgs) into the explicit `config' attribute.

Here is my full configuration if that helps: nixfiles/flake.nix at 4f290ed550186fd67b62cf9bc73efcd1b9dd5c54 · bates64/nixfiles · GitHub

Thanks very much!

You can not use the result of homeManagerConfiguration as a home-module for your system configuration.

Instead you probably want home-manager.users.bates64 = ./home/bates64/home.nix;.

2 Likes