Hi everyone,
I’m using NixOS on my desktop machine and home server, Ubuntu on my work laptop, and macOS on my personal laptop.
I’m using flakes for both NixOS and home-manager.
I can’t find a way to set my flakes up such that my main nixos flake uses the home-manager flake… Maybe I’m not understanding correctly and this isn’t actually possible? I’ve been trying to imitate it best I can by adding the home-manager module while using my personal home-manager flake as an input to import the same configurations (modules, extraSpecialArgs and such), but for some reason it doesn’t even seem to evaluate.
If anyone can shed some light on how this can be done (or refer me to another post that explains it) it would be greatly appreciated.
This is what I’ve come to currently (which doesn’t evaluate home.nix at all):
/etc/nixos/flake.nix
{
description = "Main NixOS flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nur = {
url = "github:nix-community/NUR";
inputs.nixpkgs.follows = "nixpkgs";
};
my-home.url = "path:/home/user/.config/home-manager";
};
outputs =
{
self,
nixpkgs,
home-manager,
nur,
my-home,
...
}:
{
nixosConfigurations.desktop = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./system/configuration.nix
./modules/gaming.nix
./modules/backup.nix
./modules/hyprland.nix
./modules/vm.nix
nur.modules.nixos.default
home-manager.nixosModules.home-manager
(
let
desktopInput = my-home.outputs.configurationInput "desktop";
extraSpecialArgs = desktopInput.extraSpecialArgs // {
pkgs = desktopInput.pkgs;
};
modules = desktopInput.modules;
in
{
home-manager = {
useGlobalPkgs = false;
useUserPackages = true;
users.user.imports = modules;
inherit extraSpecialArgs;
};
}
)
];
};
};
}
/home/user/.config/home-manager/flake.nix
{
description = "My Home Manager configuration";
inputs = {
nixpkgs.url = "nixpkgs/nixpkgs-unstable";
nixgl.url = "github:nix-community/nixGL";
home-manager = {
url = "github:nix-community/home-manager/master";
inputs.nixpkgs.follows = "nixpkgs";
};
nur = {
url = "github:nix-community/NUR";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
nixpkgs,
home-manager,
nixgl,
nur,
...
}:
let
lib = nixpkgs.lib;
system = "x86_64-linux";
configurationInput =
host:
let
conf = import ./hosts/${host}/conf.nix;
in
{
pkgs = import nixpkgs {
inherit system;
config.allowUnfreePredicate = pkg: builtins.elem (nixpkgs.lib.getName pkg) conf.unfree;
overlays = [ nur.overlays.default ];
};
modules = [ ./home.nix ];
extraSpecialArgs = {
inherit host;
inherit system;
hostConf = conf;
}
// (if !conf.isNixOS then { inherit nixgl; } else { });
};
in
{
homeConfigurations = {
desktop = home-manager.lib.homeManagerConfiguration configurationInput "desktop";
server = home-manager.lib.homeManagerConfiguration configurationInput "server";
work = home-manager.lib.homeManagerConfiguration configurationInput "work";
};
inherit configurationInput;
};
}
I’m sure there are probably several unconventional things / bad practices in here… I’m still learning… but I feel if I can get nixos to use the standalone home-manager I’d have an easier time tinkering and improving from there (that said, feel free to comment other improvements you think I can make if you feel like it).