refactor flake.nix for multiarch support

flake: simplify nixos hosts with nixpkgs.lib.genAttrs
This commit is contained in:
Aly Raffauf 2024-05-24 09:37:37 -04:00
parent 13167e8fb5
commit 647a36b46c
32 changed files with 161 additions and 186 deletions

View file

@ -3,9 +3,13 @@
config,
pkgs,
lib,
unstable,
...
}: {
}: let
unstable = import inputs.nixpkgsUnstable {
system = pkgs.system;
config.allowUnfree = true;
};
in {
imports = [./homeManagerModules];
home.username = "aly";
home.homeDirectory = "/home/aly";

View file

@ -116,7 +116,7 @@
"type": "github"
}
},
"nixpkgs-unstable": {
"nixpkgsUnstable": {
"locked": {
"lastModified": 1716330097,
"narHash": "sha256-8BO3B7e3BiyIDsaKA0tY8O88rClYRTjvAp66y+VBUeU=",
@ -139,7 +139,7 @@
"jovian": "jovian",
"nixos-hardware": "nixos-hardware",
"nixpkgs": "nixpkgs",
"nixpkgs-unstable": "nixpkgs-unstable"
"nixpkgsUnstable": "nixpkgsUnstable"
}
}
},

139
flake.nix
View file

@ -12,24 +12,18 @@
};
# Unstable NixOS.
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
# # Unstable version of home-manager.
# home-manager-unstable = {
# url = "github:nix-community/home-manager/master";
# inputs.nixpkgs.follows = "nixpkgs-unstable";
# };
nixpkgsUnstable.url = "github:nixos/nixpkgs/nixos-unstable";
# Automated disk partitioning.
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
# impermanence.url = "github:nix-community/impermanence";
# Pre-baked hardware support for various devices.
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
# Useful modules for Steam Deck.
jovian = {
url = "github:Jovian-Experiments/Jovian-NixOS";
inputs.nixpkgs.follows = "nixpkgs";
@ -43,106 +37,33 @@
];
};
outputs = inputs @ {
nixpkgs,
nixpkgs-unstable,
home-manager,
nixos-hardware,
disko,
jovian,
...
}: let
system = "x86_64-linux";
nixosModules = [
disko.nixosModules.disko
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.extraSpecialArgs = {inherit inputs unstable;};
home-manager.sharedModules = [{imports = [./homeManagerModules];}];
home-manager.backupFileExtension = "backup";
outputs = inputs @ {self, ...}: {
formatter = inputs.nixpkgs.lib.genAttrs [
"aarch64-darwin"
"aarch64-linux"
"x86_64-darwin"
"x86_64-linux"
] (system: inputs.nixpkgs.legacyPackages.${system}.alejandra);
nixosModules.default =
import ./nixosModules inputs;
nixosConfigurations =
inputs.nixpkgs.lib.genAttrs [
"fallarbor"
"lavaridge"
"mauville"
"mossdeep"
"petalburg"
"rustboro"
] (
host:
inputs.nixpkgs.lib.nixosSystem {
specialArgs = {inherit inputs self;};
modules = [
./hosts/${host}
];
}
./nixosModules
];
unstable = import nixpkgs-unstable {
inherit system;
config.allowUnfree = true;
};
specialArgs = {inherit inputs unstable;};
in {
formatter.${system} = nixpkgs.legacyPackages.${system}.alejandra;
nixosConfigurations = {
# Steam Deck OLED
mossdeep = nixpkgs.lib.nixosSystem rec {
inherit system specialArgs;
modules =
nixosModules
++ [
./hosts/mossdeep
jovian.nixosModules.default
nixos-hardware.nixosModules.common-pc-laptop-ssd
];
};
# Framework 13 with AMD Ryzen 7640U and 32GB RAM.
lavaridge = nixpkgs.lib.nixosSystem rec {
inherit system specialArgs;
modules =
nixosModules
++ [
./hosts/lavaridge
nixos-hardware.nixosModules.framework-13-7040-amd
];
};
# Framework 13 with 11th Gen Intel Core i5 and 16GB RAM.
fallarbor = nixpkgs.lib.nixosSystem rec {
inherit system specialArgs;
modules =
nixosModules
++ [
./hosts/fallarbor
nixos-hardware.nixosModules.framework-11th-gen-intel
];
};
# Home Lab. Ryzen 5 2600 with 16GB RAM, RX 6700.
mauville = nixpkgs.lib.nixosSystem rec {
inherit system specialArgs;
modules =
nixosModules
++ [
./hosts/mauville
nixos-hardware.nixosModules.common-cpu-amd
nixos-hardware.nixosModules.common-pc-ssd
];
};
# Lenovo Yoga 9i with i7-1360P and 16GB RAM.
petalburg = nixpkgs.lib.nixosSystem rec {
inherit system specialArgs;
modules =
nixosModules
++ [
./hosts/petalburg
nixos-hardware.nixosModules.common-cpu-intel
nixos-hardware.nixosModules.common-pc-laptop-ssd
];
};
# T440p with i5-4210M and 16GB RAM.
rustboro = nixpkgs.lib.nixosSystem rec {
inherit system specialArgs;
modules =
nixosModules
++ [
./hosts/rustboro
nixos-hardware.nixosModules.common-pc-laptop-ssd
nixos-hardware.nixosModules.lenovo-thinkpad-t440p
];
};
};
);
};
}

View file

@ -4,7 +4,6 @@
config,
osConfig,
inputs,
unstable,
...
}: {
imports = [./hypridle ./hyprlock ./hyprpaper ./hyprshade];
@ -61,7 +60,7 @@
};
wayland.windowManager.hyprland.enable = true;
wayland.windowManager.hyprland.package = unstable.hyprland;
wayland.windowManager.hyprland.package = inputs.nixpkgsUnstable.legacyPackages."${pkgs.system}".hyprland;
wayland.windowManager.hyprland.extraConfig = let
modifier = "SUPER";

View file

@ -3,7 +3,6 @@
lib,
config,
inputs,
unstable,
...
}: {
imports = [./autoRotate.nix ./randomWallpaper.nix ./redShift.nix ./virtKeyboard.nix];
@ -80,7 +79,7 @@
wayland.windowManager.sway.package =
if config.alyraffauf.desktop.sway.tabletMode.enable
then pkgs.sway
else unstable.swayfx;
else inputs.nixpkgsUnstable.legacyPackages."${pkgs.system}".swayfx;
wayland.windowManager.sway.wrapperFeatures.gtk = true;
wayland.windowManager.sway.checkConfig = false;
@ -493,7 +492,7 @@
bindswitch --reload --locked lid:off output eDP-1 enable
${
if config.wayland.windowManager.sway.package == unstable.swayfx
if config.wayland.windowManager.sway.package == inputs.nixpkgsUnstable.legacyPackages."${pkgs.system}".swayfx
then "
blur enable
blur_passes 1

View file

@ -1,13 +1,17 @@
# Framework 13 with 11th gen Intel Core i5, 16GB RAM, 512GB SSD.
{
config,
inputs,
lib,
pkgs,
self,
...
}: {
imports = [
./disko.nix
./hardware-configuration.nix # Include the results of the hardware scan.
./hardware-configuration.nix
./home.nix
self.nixosModules.default
];
boot = {

View file

@ -1,4 +1,7 @@
{
{inputs, ...}: {
imports = [
inputs.disko.nixosModules.disko
];
disko.devices = {
disk = {
vdb = {

View file

@ -3,9 +3,13 @@
lib,
pkgs,
modulesPath,
inputs,
...
}: {
imports = [(modulesPath + "/installer/scan/not-detected.nix")];
imports = [
(modulesPath + "/installer/scan/not-detected.nix")
inputs.nixos-hardware.nixosModules.framework-11th-gen-intel
];
boot.initrd.availableKernelModules = ["xhci_pci" "thunderbolt" "nvme" "usb_storage" "sd_mod"];
boot.initrd.kernelModules = [];

View file

@ -5,6 +5,9 @@
lib,
...
}: {
imports = [
inputs.home-manager.nixosModules.home-manager
];
home-manager = {
users.aly = import ../../aly.nix;
users.dustin = import ../../dustin.nix;

View file

@ -1,15 +1,17 @@
# Framework Laptop 13 with AMD Ryzen 7640U, 32GB RAM, 1TB SSD.
{
inputs,
config,
pkgs,
inputs,
lib,
pkgs,
self,
...
}: {
imports = [
./hardware-configuration.nix # Include the results of the hardware scan.
./home.nix
./disko.nix
./hardware-configuration.nix
./home.nix
self.nixosModules.default
];
boot = {

View file

@ -1,4 +1,7 @@
{
{inputs, ...}: {
imports = [
inputs.disko.nixosModules.disko
];
disko.devices = {
disk = {
vdb = {

View file

@ -6,9 +6,13 @@
lib,
pkgs,
modulesPath,
inputs,
...
}: {
imports = [(modulesPath + "/installer/scan/not-detected.nix")];
imports = [
(modulesPath + "/installer/scan/not-detected.nix")
inputs.nixos-hardware.nixosModules.framework-13-7040-amd
];
boot.initrd.availableKernelModules = ["nvme" "xhci_pci" "thunderbolt" "usb_storage" "sd_mod"];
boot.initrd.kernelModules = [];

View file

@ -5,6 +5,9 @@
lib,
...
}: {
imports = [
inputs.home-manager.nixosModules.home-manager
];
home-manager = {
sharedModules = [
{

View file

@ -1,8 +1,10 @@
# Custom desktop with AMD Ryzen 5 2600, 16GB RAM, AMD Rx 6700, and 1TB SSD + 2TB HDD.
{
config,
pkgs,
input,
lib,
pkgs,
self,
...
}: let
acmeEmail = "alyraffauf@gmail.com";
@ -11,7 +13,11 @@
mediaDirectory = "/mnt/Media";
archiveDirectory = "/mnt/Archive";
in {
imports = [./hardware-configuration.nix ./home.nix];
imports = [
./hardware-configuration.nix
./home.nix
self.nixosModules.default
];
# Bootloader.
boot.loader.systemd-boot.enable = true;

View file

@ -3,9 +3,14 @@
lib,
pkgs,
modulesPath,
inputs,
...
}: {
imports = [(modulesPath + "/installer/scan/not-detected.nix")];
imports = [
(modulesPath + "/installer/scan/not-detected.nix")
inputs.nixos-hardware.nixosModules.common-cpu-amd
inputs.nixos-hardware.nixosModules.common-pc-ssd
];
boot.initrd.availableKernelModules = ["xhci_pci" "ahci" "nvme" "usbhid" "sd_mod"];
boot.initrd.kernelModules = [];

View file

@ -5,6 +5,9 @@
lib,
...
}: {
imports = [
inputs.home-manager.nixosModules.home-manager
];
home-manager = {
sharedModules = [
{

View file

@ -1,15 +1,18 @@
# Framework Laptop 13 with AMD Ryzen 7640U, 32GB RAM, 1TB SSD.
# Steam Deck OLED
{
inputs,
config,
pkgs,
inputs,
lib,
pkgs,
self,
...
}: {
imports = [
./hardware-configuration.nix # Include the results of the hardware scan.
./home.nix
./disko.nix
./hardware-configuration.nix
./home.nix
self.nixosModules.default
inputs.jovian.nixosModules.default
];
boot = {

View file

@ -1,4 +1,7 @@
{
{inputs, ...}: {
imports = [
inputs.disko.nixosModules.disko
];
disko.devices = {
disk = {
vdb = {

View file

@ -6,9 +6,13 @@
lib,
pkgs,
modulesPath,
inputs,
...
}: {
imports = [(modulesPath + "/installer/scan/not-detected.nix")];
imports = [
(modulesPath + "/installer/scan/not-detected.nix")
inputs.nixos-hardware.nixosModules.common-pc-laptop-ssd
];
boot.initrd.availableKernelModules = ["nvme" "xhci_pci" "usb_storage" "sd_mod"];
boot.initrd.kernelModules = ["amdgpu"];

View file

@ -5,6 +5,9 @@
lib,
...
}: {
imports = [
inputs.home-manager.nixosModules.home-manager
];
home-manager = {
users.aly = import ../../aly.nix;
};

View file

@ -1,14 +1,17 @@
# Lenovo Yoga 9i Convertible with Intel Core i7-1360P, 15GB RAM, 512GB SSD.
{
config,
inputs,
lib,
pkgs,
self,
...
}: {
imports = [
./disko.nix
./hardware-configuration.nix # Include the results of the hardware scan.
./hardware-configuration.nix
./home.nix
self.nixosModules.default
];
boot = {

View file

@ -1,4 +1,7 @@
{
{inputs, ...}: {
imports = [
inputs.disko.nixosModules.disko
];
disko.devices = {
disk = {
vdb = {

View file

@ -3,9 +3,14 @@
lib,
pkgs,
modulesPath,
inputs,
...
}: {
imports = [(modulesPath + "/installer/scan/not-detected.nix")];
imports = [
(modulesPath + "/installer/scan/not-detected.nix")
inputs.nixos-hardware.nixosModules.common-cpu-intel
inputs.nixos-hardware.nixosModules.common-pc-laptop-ssd
];
boot.initrd.availableKernelModules = ["xhci_pci" "thunderbolt" "nvme" "usb_storage" "sd_mod"];
boot.initrd.kernelModules = [];

View file

@ -5,6 +5,9 @@
lib,
...
}: {
imports = [
inputs.home-manager.nixosModules.home-manager
];
home-manager = {
sharedModules = [
{

View file

@ -1,14 +1,17 @@
# Lenovo Thinkpad T440p with a Core i5 4210M, 16GB RAM, 512GB SSD.
{
config,
inputs,
lib,
pkgs,
self,
...
}: {
imports = [
./hardware-configuration.nix # Include the results of the hardware scan.
./home.nix
./disko.nix
./hardware-configuration.nix
./home.nix
self.nixosModules.default
];
boot = {
@ -16,31 +19,6 @@
loader.systemd-boot.enable = true;
loader.efi.canTouchEfiVariables = true;
};
# initrd.postDeviceCommands = lib.mkAfter ''
# mkdir /btrfs_tmp
# mount /dev/sda2 /btrfs_tmp
# if [[ -e /btrfs_tmp/rootfs ]]; then
# mkdir -p /btrfs_tmp/old_roots
# timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/rootfs)" "+%Y-%m-%-d_%H:%M:%S")
# mv /btrfs_tmp/rootfs "/btrfs_tmp/old_roots/$timestamp"
# fi
# delete_subvolume_recursively() {
# IFS=$'\n'
# for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do
# delete_subvolume_recursively "/btrfs_tmp/$i"
# done
# btrfs subvolume delete "$1"
# }
# for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +5); do
# delete_subvolume_recursively "$i"
# done
# btrfs subvolume create /btrfs_tmp/rootfs
# umount /btrfs_tmp
# '';
# };
networking.hostName = "rustboro"; # Define your hostname.
@ -82,17 +60,5 @@
tailscale.enable = true;
};
};
# environment.persistence."/persist" = {
# hideMounts = true;
# directories = [
# "/etc/NetworkManager/system-connections"
# "/etc/ssh"
# ];
# files = [
# "/etc/machine-id"
# ];
# };
system.stateVersion = "24.05";
}

View file

@ -1,4 +1,7 @@
{
{inputs, ...}: {
imports = [
inputs.disko.nixosModules.disko
];
disko.devices = {
disk = {
vdb = {

View file

@ -3,9 +3,14 @@
lib,
pkgs,
modulesPath,
inputs,
...
}: {
imports = [(modulesPath + "/installer/scan/not-detected.nix")];
imports = [
(modulesPath + "/installer/scan/not-detected.nix")
inputs.nixos-hardware.nixosModules.common-pc-laptop-ssd
inputs.nixos-hardware.nixosModules.lenovo-thinkpad-t440p
];
boot.initrd.availableKernelModules = [
"xhci_pci"

View file

@ -5,6 +5,9 @@
lib,
...
}: {
imports = [
inputs.home-manager.nixosModules.home-manager
];
home-manager = {
sharedModules = [
{

View file

@ -1,4 +1,4 @@
{
inputs: {
config,
pkgs,
...

View file

@ -3,7 +3,6 @@
pkgs,
lib,
config,
unstable,
...
}: {
options = {
@ -29,7 +28,7 @@
gnupg.agent.pinentryPackage = pkgs.pinentry-gnome3;
hyprland = {
enable = true;
package = unstable.hyprland;
package = inputs.nixpkgsUnstable.legacyPackages."${pkgs.system}".hyprland;
};
};
};

View file

@ -3,7 +3,6 @@
pkgs,
lib,
config,
unstable,
...
}: {
options = {
@ -30,7 +29,7 @@
gnupg.agent.pinentryPackage = pkgs.pinentry-gnome3;
sway = {
enable = true;
package = unstable.swayfx;
package = inputs.nixpkgsUnstable.legacyPackages."${pkgs.system}".swayfx;
};
};
};

View file

@ -6,7 +6,17 @@
unstable,
...
}: {
imports = [./aly ./dustin];
imports = [
inputs.home-manager.nixosModules.home-manager
./aly
./dustin
];
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.extraSpecialArgs = {inherit inputs unstable;};
home-manager.sharedModules = [{imports = [../../homeManagerModules];}];
home-manager.backupFileExtension = "backup";
users.mutableUsers = false;
users.users.root.openssh.authorizedKeys.keys = [