Major config overhaul: use custom modules, setup for multi-host config, and less boilerplate
This commit is contained in:
219
flake.nix
219
flake.nix
@@ -3,57 +3,11 @@
|
||||
|
||||
outputs = inputs@{ self, ... }:
|
||||
let
|
||||
# ---- SYSTEM SETTINGS ---- #
|
||||
systemSettings = {
|
||||
system = "x86_64-linux"; # system arch
|
||||
hostname = "snowfire"; # hostname
|
||||
profile = "personal"; # select a profile defined from my profiles directory
|
||||
timezone = "America/Chicago"; # select timezone
|
||||
locale = "en_US.UTF-8"; # select locale
|
||||
bootMode = "uefi"; # uefi or bios
|
||||
bootMountPath = "/boot"; # mount path for efi boot partition; only used for uefi boot mode
|
||||
grubDevice = ""; # device identifier for grub; only used for legacy (bios) boot mode
|
||||
gpuType = "amd"; # amd, intel or nvidia; only makes some slight mods for amd at the moment
|
||||
};
|
||||
|
||||
# ----- USER SETTINGS ----- #
|
||||
userSettings = rec {
|
||||
username = "emmet"; # username
|
||||
name = "Emmet"; # name/identifier
|
||||
email = "emmet@librephoenix.com"; # email (used for certain configurations)
|
||||
dotfilesDir = "~/.dotfiles"; # absolute path of the local repo
|
||||
theme = "io"; # selcted theme from my themes directory (./themes/)
|
||||
wm = "hyprland"; # Selected window manager or desktop environment; must select one in both ./user/wm/ and ./system/wm/
|
||||
# window manager type (hyprland or x11) translator
|
||||
wmType = if (wm == "hyprland") then "wayland" else "x11";
|
||||
browser = "qutebrowser"; # Default browser; must select one from ./user/app/browser/
|
||||
spawnBrowser = if ((browser == "qutebrowser") && (wm == "hyprland")) then "qutebrowser-hyprprofile" else (if (browser == "qutebrowser") then "qutebrowser --qt-flag ignore-gpu-blacklist --qt-flag enable-gpu-rasterization --qt-flag enable-native-gpu-memory-buffers --qt-flag enable-accelerated-2d-canvas --qt-flag num-raster-threads=4" else browser); # Browser spawn command must be specail for qb, since it doesn't gpu accelerate by default (why?)
|
||||
defaultRoamDir = "Personal.p"; # Default org roam directory relative to ~/Org
|
||||
term = "alacritty"; # Default terminal command;
|
||||
font = "Intel One Mono"; # Selected font
|
||||
fontPkg = pkgs.intel-one-mono; # Font package
|
||||
editor = "emacsclient"; # Default editor;
|
||||
# editor spawning translator
|
||||
# generates a command that can be used to spawn editor inside a gui
|
||||
# EDITOR and TERM session variables must be set in home.nix or other module
|
||||
# I set the session variable SPAWNEDITOR to this in my home.nix for convenience
|
||||
spawnEditor = if (editor == "emacsclient") then
|
||||
"emacsclient -c -a 'emacs'"
|
||||
else
|
||||
(if ((editor == "vim") ||
|
||||
(editor == "nvim") ||
|
||||
(editor == "nano")) then
|
||||
"exec " + term + " -e " + editor
|
||||
else
|
||||
(if (editor == "neovide") then
|
||||
"neovide -- --listen /tmp/nvimsocket"
|
||||
else
|
||||
editor));
|
||||
};
|
||||
system = "x86_64-linux";
|
||||
|
||||
# create patched nixpkgs
|
||||
nixpkgs-patched =
|
||||
(import inputs.nixpkgs { system = systemSettings.system; }).applyPatches {
|
||||
(import inputs.nixpkgs { inherit system; }).applyPatches {
|
||||
name = "nixpkgs-patched";
|
||||
src = inputs.nixpkgs;
|
||||
patches = [ ];
|
||||
@@ -62,135 +16,63 @@
|
||||
# configure pkgs
|
||||
# use nixpkgs if running a server (homelab or worklab profile)
|
||||
# otherwise use patched nixos-unstable nixpkgs
|
||||
pkgs = (if ((systemSettings.profile == "homelab") || (systemSettings.profile == "worklab"))
|
||||
then
|
||||
pkgs-stable
|
||||
else
|
||||
(import nixpkgs-patched {
|
||||
system = systemSettings.system;
|
||||
config = {
|
||||
allowUnfree = true;
|
||||
allowUnfreePredicate = (_: true);
|
||||
};
|
||||
overlays = [ inputs.rust-overlay.overlays.default
|
||||
inputs.emacs-overlay.overlays.default
|
||||
];
|
||||
}));
|
||||
|
||||
pkgs-stable = import inputs.nixpkgs-stable {
|
||||
system = systemSettings.system;
|
||||
pkgs = import nixpkgs-patched {
|
||||
inherit system;
|
||||
config = {
|
||||
allowUnfree = true;
|
||||
allowUnfreePredicate = (_: true);
|
||||
};
|
||||
overlays = [ inputs.rust-overlay.overlays.default inputs.emacs-overlay.overlays.default ];
|
||||
};
|
||||
|
||||
pkgs-unstable = import inputs.nixpkgs-patched {
|
||||
system = systemSettings.system;
|
||||
pkgs-stable = import inputs.nixpkgs-stable {
|
||||
inherit system;
|
||||
config = {
|
||||
allowUnfree = true;
|
||||
allowUnfreePredicate = (_: true);
|
||||
};
|
||||
overlays = [ inputs.rust-overlay.overlays.default ];
|
||||
};
|
||||
|
||||
# configure lib
|
||||
# use nixpkgs if running a server (homelab or worklab profile)
|
||||
# otherwise use patched nixos-unstable nixpkgs
|
||||
lib = (if ((systemSettings.profile == "homelab") || (systemSettings.profile == "worklab"))
|
||||
then
|
||||
inputs.nixpkgs-stable.lib
|
||||
else
|
||||
inputs.nixpkgs.lib);
|
||||
lib = inputs.nixpkgs.lib;
|
||||
|
||||
# use home-manager-stable if running a server (homelab or worklab profile)
|
||||
# otherwise use home-manager-unstable
|
||||
home-manager = (if ((systemSettings.profile == "homelab") || (systemSettings.profile == "worklab"))
|
||||
then
|
||||
inputs.home-manager-stable
|
||||
else
|
||||
inputs.home-manager-unstable);
|
||||
|
||||
# Systems that can run tests:
|
||||
supportedSystems = [ "aarch64-linux" "i686-linux" "x86_64-linux" ];
|
||||
|
||||
# Function to generate a set based on supported systems:
|
||||
forAllSystems = inputs.nixpkgs.lib.genAttrs supportedSystems;
|
||||
|
||||
# Attribute set of nixpkgs for each system:
|
||||
nixpkgsFor =
|
||||
forAllSystems (system: import inputs.nixpkgs { inherit system; });
|
||||
# create a list of all directories inside of ./hosts
|
||||
# every directory in ./hosts has config for that machine
|
||||
hosts = builtins.filter (x: x != null) (lib.mapAttrsToList (name: value: if (value == "directory") then name else null) (builtins.readDir ./hosts));
|
||||
|
||||
in {
|
||||
homeConfigurations = {
|
||||
user = home-manager.lib.homeManagerConfiguration {
|
||||
inherit pkgs;
|
||||
modules = [
|
||||
(./. + "/profiles" + ("/" + systemSettings.profile) + "/home.nix") # load home.nix from selected PROFILE
|
||||
inputs.chaotic.homeManagerModules.default
|
||||
];
|
||||
extraSpecialArgs = {
|
||||
# pass config variables from above
|
||||
inherit pkgs-stable;
|
||||
inherit pkgs-unstable;
|
||||
inherit systemSettings;
|
||||
inherit userSettings;
|
||||
inherit inputs;
|
||||
# generate a nixos configuration for every host in ./hosts
|
||||
nixosConfigurations = builtins.listToAttrs
|
||||
(map (host: {
|
||||
name = host;
|
||||
value = lib.nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
modules = [
|
||||
# host specific config
|
||||
{ config.networking.hostName = host; }
|
||||
(./hosts + "/${host}")
|
||||
|
||||
# my modules
|
||||
./modules/system
|
||||
|
||||
# home manager
|
||||
inputs.home-manager.nixosModules.home-manager
|
||||
{ home-manager.extraSpecialArgs = {
|
||||
inherit pkgs;
|
||||
inherit pkgs-stable;
|
||||
inherit inputs;
|
||||
};
|
||||
}
|
||||
|
||||
# chaos... control!
|
||||
inputs.chaotic.nixosModules.default
|
||||
];
|
||||
specialArgs = {
|
||||
inherit pkgs-stable;
|
||||
inherit inputs;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
nixosConfigurations = {
|
||||
system = lib.nixosSystem {
|
||||
system = systemSettings.system;
|
||||
modules = [
|
||||
(./. + "/profiles" + ("/" + systemSettings.profile) + "/configuration.nix")
|
||||
./system/bin/phoenix.nix
|
||||
inputs.chaotic.nixosModules.default
|
||||
]; # load configuration.nix from selected PROFILE
|
||||
specialArgs = {
|
||||
# pass config variables from above
|
||||
inherit pkgs-stable;
|
||||
inherit pkgs-unstable;
|
||||
inherit systemSettings;
|
||||
inherit userSettings;
|
||||
inherit inputs;
|
||||
};
|
||||
};
|
||||
};
|
||||
nixOnDroidConfigurations = {
|
||||
inherit pkgs;
|
||||
default = inputs.nix-on-droid.lib.nixOnDroidConfiguration {
|
||||
modules = [ ./profiles/nix-on-droid/configuration.nix ];
|
||||
};
|
||||
extraSpecialArgs = {
|
||||
# pass config variables from above
|
||||
inherit pkgs-stable;
|
||||
inherit systemSettings;
|
||||
inherit userSettings;
|
||||
inherit inputs;
|
||||
};
|
||||
};
|
||||
|
||||
packages = forAllSystems (system:
|
||||
let pkgs = nixpkgsFor.${system};
|
||||
in {
|
||||
default = self.packages.${system}.install;
|
||||
|
||||
install = pkgs.writeShellApplication {
|
||||
name = "install";
|
||||
runtimeInputs = with pkgs; [ git ]; # I could make this fancier by adding other deps
|
||||
text = ''${./install.sh} "$@"'';
|
||||
};
|
||||
});
|
||||
|
||||
apps = forAllSystems (system: {
|
||||
default = self.apps.${system}.install;
|
||||
|
||||
install = {
|
||||
type = "app";
|
||||
program = "${self.packages.${system}.install}/bin/install";
|
||||
};
|
||||
});
|
||||
}) hosts);
|
||||
};
|
||||
|
||||
inputs = {
|
||||
@@ -198,17 +80,8 @@
|
||||
nixpkgs-stable.url = "nixpkgs/nixos-24.11";
|
||||
chaotic.url = "github:chaotic-cx/nyx/5071a4037c634d41a57926521fef2e179abe3bd9";
|
||||
|
||||
home-manager-unstable.url = "github:nix-community/home-manager/master";
|
||||
home-manager-unstable.inputs.nixpkgs.follows = "nixpkgs";
|
||||
|
||||
home-manager-stable.url = "github:nix-community/home-manager/release-24.05";
|
||||
home-manager-stable.inputs.nixpkgs.follows = "nixpkgs-stable";
|
||||
|
||||
nix-on-droid = {
|
||||
url = "github:nix-community/nix-on-droid/master";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
inputs.home-manager.follows = "home-manager-unstable";
|
||||
};
|
||||
home-manager.url = "github:nix-community/home-manager/master";
|
||||
home-manager.inputs.nixpkgs.follows = "nixpkgs";
|
||||
|
||||
hyprland = {
|
||||
type = "git";
|
||||
@@ -247,5 +120,9 @@
|
||||
url = "github:StevenBlack/hosts";
|
||||
flake = false;
|
||||
};
|
||||
|
||||
secrets = {
|
||||
url = "path:/etc/nixos.secrets";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user