Clearify flake

This commit is contained in:
GRMrGecko 2024-05-16 00:18:01 -05:00
parent 6ce8b4264e
commit d781b5f7c1

View File

@ -1,6 +1,7 @@
{ {
description = "Nixos config flake"; description = "Nixos config flake";
# Package sources.
inputs = { inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11"; nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
@ -16,8 +17,10 @@
}; };
}; };
# Flake outputs, NixOS and Home Configurations.
outputs = inputs@{ self, ... }: outputs = inputs@{ self, ... }:
let let
# Load settings.nix or the default if not exists.
settings = (if (builtins.pathExists ./settings.nix) settings = (if (builtins.pathExists ./settings.nix)
then then
(import ./settings.nix) (import ./settings.nix)
@ -25,6 +28,7 @@
(import ./settings-default.nix) (import ./settings-default.nix)
); );
# Based on loaded settings, set the nixpkgs version.
nixpkgs = (if (settings.packages == "stable") nixpkgs = (if (settings.packages == "stable")
then then
inputs.nixpkgs inputs.nixpkgs
@ -32,6 +36,7 @@
inputs.nixpkgs-unstable inputs.nixpkgs-unstable
); );
# Setup an overlay for unstable packages to include on stable environments.
overlay-unstable = final: prev: { overlay-unstable = final: prev: {
unstable = import inputs.nixpkgs-unstable { unstable = import inputs.nixpkgs-unstable {
system = settings.system; system = settings.system;
@ -39,6 +44,7 @@
}; };
}; };
# Setup the main packages config with the overlays.
pkgs = (import nixpkgs { pkgs = (import nixpkgs {
system = settings.system; system = settings.system;
config = { config = {
@ -48,6 +54,7 @@
overlays = [ overlay-unstable ]; overlays = [ overlay-unstable ];
}); });
# Function to configure a system with our defaults.
mkSystem = config: nixpkgs.lib.nixosSystem { mkSystem = config: nixpkgs.lib.nixosSystem {
system = settings.system; system = settings.system;
specialArgs = { specialArgs = {
@ -62,6 +69,7 @@
]; ];
}; };
# Function to configure home-manager for a user.
mkHome = config: inputs.home-manager.lib.homeManagerConfiguration { mkHome = config: inputs.home-manager.lib.homeManagerConfiguration {
inherit pkgs; inherit pkgs;
extraSpecialArgs = { extraSpecialArgs = {
@ -71,9 +79,13 @@
modules = [ config ]; modules = [ config ];
}; };
in { in {
# NixOS configurations, in most cases we use default with a profile.
# Any host that needs specific configurations separate from what is included by default,
# will need its own configuration for its hostname.
nixosConfigurations.default = mkSystem ./hosts/default/configuration.nix; nixosConfigurations.default = mkSystem ./hosts/default/configuration.nix;
nixosConfigurations.tama = mkSystem ./hosts/tama/configuration.nix; nixosConfigurations.tama = mkSystem ./hosts/tama/configuration.nix;
# Home manager configurations, we do the main user from the configuration and root.
homeConfigurations = { homeConfigurations = {
${settings.user.name} = mkHome ./users/main-user.nix; ${settings.user.name} = mkHome ./users/main-user.nix;
"root" = mkHome ./users/root.nix; "root" = mkHome ./users/root.nix;