horribly cobble together the ability to use both home-manager switch and nixos-rebuild switch against the same flake
This commit is contained in:
parent
b792e801c5
commit
e3e28fa662
3 changed files with 296 additions and 136 deletions
157
lib/default.nix
157
lib/default.nix
|
|
@ -1,68 +1,113 @@
|
|||
{ nixpkgs, home-manager, inputs, ... }:
|
||||
{
|
||||
nixpkgs,
|
||||
home-manager,
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
allOverlays = import (../overlays) { inherit nixpkgs; };
|
||||
in
|
||||
{
|
||||
# It's not really that I care about whether a system is a desktop system or
|
||||
# a server system, but moreso that I care about whether a system is headless or not.
|
||||
# I also care about things like if it's darwin, or wsl.
|
||||
# TODO: Expand this to actually make use of extraSpecialArgs and pass special
|
||||
# args to the relevant places.
|
||||
mkSystem = {
|
||||
hostname,
|
||||
system ? "x86_64-linux",
|
||||
users ? [],
|
||||
extraModules ? [],
|
||||
extraSpecialArgs ? {}
|
||||
}:
|
||||
let
|
||||
pkgs_with_overlays = import nixpkgs {
|
||||
getPkgs =
|
||||
system:
|
||||
import nixpkgs {
|
||||
inherit system;
|
||||
overlays = allOverlays;
|
||||
};
|
||||
hostModule = import ../hosts/${hostname} {
|
||||
inherit inputs;
|
||||
pkgs = pkgs_with_overlays;
|
||||
};
|
||||
userModules = map (name:
|
||||
import ../users/${name} {
|
||||
pkgs = pkgs_with_overlays;
|
||||
lib = nixpkgs.lib;
|
||||
}
|
||||
) users;
|
||||
|
||||
homeUserNames = builtins.filter (name:
|
||||
builtins.pathExists ../users/${name}/home.nix
|
||||
) users;
|
||||
|
||||
homeUsers = nixpkgs.lib.listToAttrs (map (name: {
|
||||
name = name;
|
||||
value = import ../users/${name}/home.nix {
|
||||
username = name;
|
||||
pkgs = pkgs_with_overlays;
|
||||
lib = nixpkgs.lib;
|
||||
in
|
||||
{
|
||||
mkSystem =
|
||||
{
|
||||
hostname,
|
||||
system ? "x86_64-linux",
|
||||
users ? [ ],
|
||||
extraModules ? [ ],
|
||||
homeUsers ? { },
|
||||
extraSpecialArgs ? { },
|
||||
}:
|
||||
let
|
||||
pkgs_with_overlays = import nixpkgs {
|
||||
inherit system;
|
||||
overlays = allOverlays;
|
||||
};
|
||||
}) homeUserNames);
|
||||
in
|
||||
hostModule = import ../hosts/${hostname} {
|
||||
inherit inputs;
|
||||
pkgs = pkgs_with_overlays;
|
||||
};
|
||||
userModules = map (
|
||||
name:
|
||||
import ../users/${name} {
|
||||
pkgs = pkgs_with_overlays;
|
||||
lib = nixpkgs.lib;
|
||||
}
|
||||
) users;
|
||||
|
||||
formattedHomeUsers = nixpkgs.lib.mapAttrs (username: moduleList: {
|
||||
imports = moduleList;
|
||||
}) homeUsers;
|
||||
in
|
||||
nixpkgs.lib.nixosSystem {
|
||||
inherit system;
|
||||
# pkgs = import inputs.nixpkgs {
|
||||
# inherit system;
|
||||
# overlays = allOverlays;
|
||||
# config = { allowUnfree = true; nvidia.acceptLicense = true; };
|
||||
# };
|
||||
modules = [ hostModule ]
|
||||
++ userModules
|
||||
++ extraModules
|
||||
++ (if homeUserNames != [] then [
|
||||
home-manager.nixosModules.home-manager
|
||||
{
|
||||
home-manager.backupFileExtension = "hm-bak";
|
||||
home-manager.users = homeUsers;
|
||||
}
|
||||
] else []);
|
||||
modules = [
|
||||
hostModule
|
||||
]
|
||||
++ userModules
|
||||
++ extraModules
|
||||
++ (
|
||||
if homeUsers != { } then
|
||||
[
|
||||
home-manager.nixosModules.home-manager
|
||||
{
|
||||
#home-manager.useGlobalPkgs = true; # NOTE: Incompatible with nixpkgs.{config,overlays}
|
||||
home-manager.useUserPackages = true;
|
||||
home-manager.backupFileExtension = "hm-bak";
|
||||
|
||||
# Directly inject the module lists? (isn't this the problem?)
|
||||
home-manager.users = formattedHomeUsers;
|
||||
home-manager.extraSpecialArgs = { inherit inputs; };
|
||||
}
|
||||
]
|
||||
else
|
||||
[ ]
|
||||
);
|
||||
specialArgs = {
|
||||
inherit inputs hostname;
|
||||
} // extraSpecialArgs;
|
||||
}
|
||||
// extraSpecialArgs;
|
||||
};
|
||||
|
||||
getUserHomeModule =
|
||||
username: pkgs: inputs:
|
||||
import ../users/${username}/home.nix {
|
||||
inherit username pkgs inputs;
|
||||
lib = nixpkgs.lib;
|
||||
};
|
||||
|
||||
/**
|
||||
This function returns an attribute set { module, config }.
|
||||
*/
|
||||
mkHome =
|
||||
{
|
||||
username,
|
||||
system ? "x86_64-linux",
|
||||
extraModules ? [ ],
|
||||
}:
|
||||
let
|
||||
pkgs_with_overlays = getPkgs system;
|
||||
moduleList = [
|
||||
(import ../users/${username}/home.nix {
|
||||
inherit inputs username;
|
||||
pkgs = pkgs_with_overlays;
|
||||
lib = nixpkgs.lib;
|
||||
})
|
||||
]
|
||||
++ extraModules;
|
||||
in
|
||||
{
|
||||
module = moduleList;
|
||||
config = home-manager.lib.homeManagerConfiguration {
|
||||
pkgs = pkgs_with_overlays;
|
||||
modules = moduleList;
|
||||
};
|
||||
};
|
||||
|
||||
mkHomeConfigs = userProfiles: nixpkgs.lib.mapAttrs (username: profile: profile.config) userProfiles;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue