config/lib/mkSystem.nix

112 lines
2.9 KiB
Nix
Raw Normal View History

2025-04-18 16:46:54 -07:00
# This function creates a NixOS system based on our VM setup for a
# particular architecture.
{
nixpkgs,
overlays,
inputs,
userSettings,
2025-04-18 16:46:54 -07:00
}: name: {
system,
darwin ? false,
extraModules ? [],
}: let
2025-04-19 10:06:25 -07:00
nixindex =
if darwin
then inputs.nix-index-database.darwinModules.nix-index
else inputs.nix-index-database.nixosModules.nix-index;
2025-04-18 16:46:54 -07:00
2025-04-21 13:04:42 -07:00
stylix =
if darwin
then inputs.stylix.darwinModules.stylix
else inputs.stylix.nixosModules.stylix;
systemSettings = rec {
2025-04-21 14:46:41 -07:00
inherit darwin;
host =
if darwin
2025-04-21 13:04:42 -07:00
then userSettings.darwinHost
else userSettings.nixosHost;
2025-04-18 16:46:54 -07:00
# The config files for this system.
2025-04-18 16:46:54 -07:00
hostConfig = ../hosts/${host}/configuration.nix;
homeConfig = ../hosts/${host}/home.nix;
2025-04-18 16:46:54 -07:00
homeDir =
if darwin
then "/Users/" + userSettings.username + "/"
else "/home/" + userSettings.username + "/";
2025-04-19 11:04:56 -07:00
# NixOS vs nix-darwin functions
systemFunc =
if darwin
then inputs.darwin.lib.darwinSystem
else nixpkgs.lib.nixosSystem;
2025-04-19 10:06:25 -07:00
hmModules =
if darwin
then inputs.home-manager.darwinModules
else inputs.home-manager.nixosModules;
};
2025-04-18 16:46:54 -07:00
in
with systemSettings;
systemFunc rec {
inherit system;
#gross and ugly hack do NOT like
specialArgs = {
inherit (userSettings) darwinTiling;
};
modules =
[
# Apply our overlays. Overlays are keyed by system type so we have
# to go through and apply our system type. We do this first so
# the overlays are available globally.
{nixpkgs.overlays = overlays;}
2025-04-18 16:46:54 -07:00
# Enable caching for nix-index so we dont have to rebuild it
2025-04-19 10:06:25 -07:00
#shared modules
2025-05-01 12:41:47 -07:00
../modules/shared
2025-04-19 10:06:25 -07:00
2025-04-21 13:04:42 -07:00
# Link to config.nix
hostConfig
2025-04-21 13:04:42 -07:00
#Set up nix-index and enable comma for easy one-shot command use
#https://github.com/nix-community/comma
nixindex
{programs.nix-index-database.comma.enable = true;}
2025-04-21 13:04:42 -07:00
#style programs
stylix
hmModules.home-manager
{
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
backupFileExtension = "hm-backup";
extraSpecialArgs = {inherit inputs userSettings systemSettings;};
users.${userSettings.username} = homeConfig;
};
2025-04-19 10:06:25 -07:00
users.users.${userSettings.username}.home = homeDir;
}
2025-04-19 13:50:58 -07:00
# We expose some extra arguments so that our modules can parameterize
# better based on these values.
{
config._module.args = {
currentSystem = system;
# currentSystemName = name;
# currentSystemUser = userSettings.username;
2025-04-18 16:46:54 -07:00
inherit inputs userSettings systemSettings;
};
}
]
2025-04-21 13:04:42 -07:00
#Add extra modules depending on system
++ extraModules;
}