119 lines
3 KiB
Nix
119 lines
3 KiB
Nix
# This function creates a NixOS system based on our VM setup for a
|
|
# particular architecture.
|
|
{
|
|
nixpkgs,
|
|
overlays,
|
|
inputs,
|
|
userSettings,
|
|
}: name: {
|
|
system,
|
|
darwin ? false,
|
|
extraModules ? [],
|
|
}: let
|
|
nixindex =
|
|
if darwin
|
|
then inputs.nix-index-database.darwinModules.nix-index
|
|
else inputs.nix-index-database.nixosModules.nix-index;
|
|
|
|
stylix =
|
|
if darwin
|
|
then inputs.stylix.darwinModules.stylix
|
|
else inputs.stylix.nixosModules.stylix;
|
|
|
|
systemModuleDir =
|
|
if darwin
|
|
then "macos"
|
|
else "nixos";
|
|
|
|
systemSettings = rec {
|
|
inherit darwin;
|
|
host =
|
|
if darwin
|
|
then userSettings.darwinHost
|
|
else userSettings.nixosHost;
|
|
|
|
# The config files for this system.
|
|
|
|
hostConfig = ../hosts/${host}/configuration.nix;
|
|
homeConfig = ../hosts/${host}/home.nix;
|
|
|
|
homeDir =
|
|
if darwin
|
|
then "/Users/" + userSettings.username + "/"
|
|
else "/home/" + userSettings.username + "/";
|
|
|
|
# NixOS vs nix-darwin functions
|
|
systemFunc =
|
|
if darwin
|
|
then inputs.darwin.lib.darwinSystem
|
|
else nixpkgs.lib.nixosSystem;
|
|
|
|
hmModules =
|
|
if darwin
|
|
then inputs.home-manager.darwinModules
|
|
else inputs.home-manager.nixosModules;
|
|
};
|
|
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;}
|
|
|
|
# Enable caching for nix-index so we dont have to rebuild it
|
|
|
|
#shared modules
|
|
../modules/shared
|
|
|
|
#system specific modules
|
|
../modules/${systemModuleDir}
|
|
|
|
# Link to config.nix
|
|
hostConfig
|
|
|
|
#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;}
|
|
|
|
#style programs
|
|
stylix
|
|
|
|
hmModules.home-manager
|
|
{
|
|
home-manager = {
|
|
useGlobalPkgs = true;
|
|
useUserPackages = true;
|
|
backupFileExtension = "hm-backup";
|
|
extraSpecialArgs = {inherit inputs userSettings systemSettings;};
|
|
users.${userSettings.username} = homeConfig;
|
|
};
|
|
|
|
users.users.${userSettings.username}.home = homeDir;
|
|
}
|
|
|
|
# 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;
|
|
|
|
inherit inputs userSettings systemSettings;
|
|
};
|
|
}
|
|
]
|
|
#Add extra modules depending on system
|
|
++ extraModules;
|
|
}
|