nixos/flake.nix

113 lines
3.4 KiB
Nix
Raw Permalink Normal View History

2024-05-14 09:29:16 -05:00
{
description = "Nixos config flake";
2024-05-16 00:18:01 -05:00
# Package sources.
2024-05-14 09:29:16 -05:00
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
2024-05-14 09:29:16 -05:00
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager = {
url = "github:nix-community/home-manager/release-24.05";
2024-05-16 00:35:55 -05:00
inputs.nixpkgs.follows = "nixpkgs";
};
home-manager-unstable = {
2024-05-14 09:29:16 -05:00
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
2024-09-08 23:30:03 -05:00
flatpaks.url = "github:GermanBread/declarative-flatpak/stable-v3";
2024-05-14 09:29:16 -05:00
};
2024-05-16 00:18:01 -05:00
# Flake outputs, NixOS and Home Configurations.
outputs = inputs@{ self, flatpaks, ... }:
2024-05-14 09:29:16 -05:00
let
2024-05-16 00:18:01 -05:00
# Load settings.nix or the default if not exists.
2024-05-14 09:29:16 -05:00
settings = (if (builtins.pathExists ./settings.nix)
then
(import ./settings.nix)
else
(import ./settings-default.nix)
);
2024-05-16 00:18:01 -05:00
# Based on loaded settings, set the nixpkgs version.
2024-05-14 09:29:16 -05:00
nixpkgs = (if (settings.packages == "stable")
then
inputs.nixpkgs
else
inputs.nixpkgs-unstable
);
2024-05-16 00:35:55 -05:00
# Based on loaded settings, set the home-manager version.
home-manager = (if (settings.packages == "stable")
then
inputs.home-manager
else
inputs.home-manager-unstable
);
2024-05-16 00:18:01 -05:00
# Setup an overlay for unstable packages to include on stable environments.
2024-05-14 09:29:16 -05:00
overlay-unstable = final: prev: {
unstable = import inputs.nixpkgs-unstable {
system = settings.system;
config.allowUnfree = true;
};
};
2024-05-16 00:18:01 -05:00
# Setup the main packages config with the overlays.
2024-05-14 09:29:16 -05:00
pkgs = (import nixpkgs {
system = settings.system;
config = {
allowUnfree = true;
allowUnfreePredicate = (_: true);
};
overlays = [ overlay-unstable ];
});
2024-05-16 00:18:01 -05:00
# Function to configure a system with our defaults.
2024-05-14 09:29:16 -05:00
mkSystem = config: nixpkgs.lib.nixosSystem {
system = settings.system;
specialArgs = {
inherit inputs;
inherit pkgs;
inherit settings;
};
modules = [
inputs.disko.nixosModules.disko
2024-05-16 00:35:55 -05:00
home-manager.nixosModules.default
flatpaks.nixosModules.default
config
2024-05-14 09:29:16 -05:00
];
};
2024-05-16 00:18:01 -05:00
# Function to configure home-manager for a user.
2024-05-16 00:35:55 -05:00
mkHome = config: home-manager.lib.homeManagerConfiguration {
2024-05-14 09:29:16 -05:00
inherit pkgs;
extraSpecialArgs = {
inherit inputs;
inherit settings;
};
modules = [
flatpaks.homeManagerModules.default
config
];
2024-05-14 09:29:16 -05:00
};
in {
2024-05-16 00:18:01 -05:00
# 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.
2024-05-14 09:29:16 -05:00
nixosConfigurations.default = mkSystem ./hosts/default/configuration.nix;
nixosConfigurations.tama = mkSystem ./hosts/tama/configuration.nix;
2024-05-16 00:18:01 -05:00
# Home manager configurations, we do the main user from the configuration and root.
2024-05-14 09:29:16 -05:00
homeConfigurations = {
${settings.user.name} = mkHome ./users/main-user.nix;
"root" = mkHome ./users/root.nix;
2024-05-14 09:29:16 -05:00
};
};
}