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, config,
pkgs, pkgs,
lib, lib,
unstable,
... ...
}: { }: let
unstable = import inputs.nixpkgsUnstable {
system = pkgs.system;
config.allowUnfree = true;
};
in {
imports = [./homeManagerModules]; imports = [./homeManagerModules];
home.username = "aly"; home.username = "aly";
home.homeDirectory = "/home/aly"; home.homeDirectory = "/home/aly";

View file

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

137
flake.nix
View file

@ -12,24 +12,18 @@
}; };
# Unstable NixOS. # Unstable NixOS.
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable"; nixpkgsUnstable.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";
# };
# Automated disk partitioning.
disko = { disko = {
url = "github:nix-community/disko"; url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
# impermanence.url = "github:nix-community/impermanence";
# Pre-baked hardware support for various devices. # Pre-baked hardware support for various devices.
nixos-hardware.url = "github:NixOS/nixos-hardware/master"; nixos-hardware.url = "github:NixOS/nixos-hardware/master";
# Useful modules for Steam Deck.
jovian = { jovian = {
url = "github:Jovian-Experiments/Jovian-NixOS"; url = "github:Jovian-Experiments/Jovian-NixOS";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
@ -43,106 +37,33 @@
]; ];
}; };
outputs = inputs @ { outputs = inputs @ {self, ...}: {
nixpkgs, formatter = inputs.nixpkgs.lib.genAttrs [
nixpkgs-unstable, "aarch64-darwin"
home-manager, "aarch64-linux"
nixos-hardware, "x86_64-darwin"
disko, "x86_64-linux"
jovian, ] (system: inputs.nixpkgs.legacyPackages.${system}.alejandra);
...
}: 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";
}
./nixosModules
];
unstable = import nixpkgs-unstable {
inherit system;
config.allowUnfree = true;
};
specialArgs = {inherit inputs unstable;};
in {
formatter.${system} = nixpkgs.legacyPackages.${system}.alejandra;
nixosConfigurations = { nixosModules.default =
# Steam Deck OLED import ./nixosModules inputs;
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. nixosConfigurations =
lavaridge = nixpkgs.lib.nixosSystem rec { inputs.nixpkgs.lib.genAttrs [
inherit system specialArgs; "fallarbor"
modules = "lavaridge"
nixosModules "mauville"
++ [ "mossdeep"
./hosts/lavaridge "petalburg"
nixos-hardware.nixosModules.framework-13-7040-amd "rustboro"
]; ] (
}; host:
inputs.nixpkgs.lib.nixosSystem {
# Framework 13 with 11th Gen Intel Core i5 and 16GB RAM. specialArgs = {inherit inputs self;};
fallarbor = nixpkgs.lib.nixosSystem rec { modules = [
inherit system specialArgs; ./hosts/${host}
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, config,
osConfig, osConfig,
inputs, inputs,
unstable,
... ...
}: { }: {
imports = [./hypridle ./hyprlock ./hyprpaper ./hyprshade]; imports = [./hypridle ./hyprlock ./hyprpaper ./hyprshade];
@ -61,7 +60,7 @@
}; };
wayland.windowManager.hyprland.enable = true; 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 wayland.windowManager.hyprland.extraConfig = let
modifier = "SUPER"; modifier = "SUPER";

View file

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

View file

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

View file

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

View file

@ -3,9 +3,13 @@
lib, lib,
pkgs, pkgs,
modulesPath, 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.availableKernelModules = ["xhci_pci" "thunderbolt" "nvme" "usb_storage" "sd_mod"];
boot.initrd.kernelModules = []; boot.initrd.kernelModules = [];

View file

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

View file

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

View file

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

View file

@ -6,9 +6,13 @@
lib, lib,
pkgs, pkgs,
modulesPath, 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.availableKernelModules = ["nvme" "xhci_pci" "thunderbolt" "usb_storage" "sd_mod"];
boot.initrd.kernelModules = []; boot.initrd.kernelModules = [];

View file

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

View file

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

View file

@ -3,9 +3,14 @@
lib, lib,
pkgs, pkgs,
modulesPath, 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.availableKernelModules = ["xhci_pci" "ahci" "nvme" "usbhid" "sd_mod"];
boot.initrd.kernelModules = []; boot.initrd.kernelModules = [];

View file

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

View file

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

View file

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

View file

@ -6,9 +6,13 @@
lib, lib,
pkgs, pkgs,
modulesPath, 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.availableKernelModules = ["nvme" "xhci_pci" "usb_storage" "sd_mod"];
boot.initrd.kernelModules = ["amdgpu"]; boot.initrd.kernelModules = ["amdgpu"];

View file

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

View file

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

View file

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

View file

@ -3,9 +3,14 @@
lib, lib,
pkgs, pkgs,
modulesPath, 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.availableKernelModules = ["xhci_pci" "thunderbolt" "nvme" "usb_storage" "sd_mod"];
boot.initrd.kernelModules = []; boot.initrd.kernelModules = [];

View file

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

View file

@ -1,14 +1,17 @@
# Lenovo Thinkpad T440p with a Core i5 4210M, 16GB RAM, 512GB SSD. # Lenovo Thinkpad T440p with a Core i5 4210M, 16GB RAM, 512GB SSD.
{ {
config, config,
inputs,
lib, lib,
pkgs, pkgs,
self,
... ...
}: { }: {
imports = [ imports = [
./hardware-configuration.nix # Include the results of the hardware scan.
./home.nix
./disko.nix ./disko.nix
./hardware-configuration.nix
./home.nix
self.nixosModules.default
]; ];
boot = { boot = {
@ -16,31 +19,6 @@
loader.systemd-boot.enable = true; loader.systemd-boot.enable = true;
loader.efi.canTouchEfiVariables = 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. networking.hostName = "rustboro"; # Define your hostname.
@ -82,17 +60,5 @@
tailscale.enable = true; tailscale.enable = true;
}; };
}; };
# environment.persistence."/persist" = {
# hideMounts = true;
# directories = [
# "/etc/NetworkManager/system-connections"
# "/etc/ssh"
# ];
# files = [
# "/etc/machine-id"
# ];
# };
system.stateVersion = "24.05"; system.stateVersion = "24.05";
} }

View file

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

View file

@ -3,9 +3,14 @@
lib, lib,
pkgs, pkgs,
modulesPath, 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 = [ boot.initrd.availableKernelModules = [
"xhci_pci" "xhci_pci"

View file

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

View file

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

View file

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

View file

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

View file

@ -6,7 +6,17 @@
unstable, 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.mutableUsers = false;
users.users.root.openssh.authorizedKeys.keys = [ users.users.root.openssh.authorizedKeys.keys = [