This repository has been archived on 2024-07-08. You can view files and clone it, but cannot push or open issues or pull requests.
nix-config-tn/flake.nix

297 lines
9 KiB
Nix
Raw Normal View History

2024-03-13 06:55:17 -05:00
{
description = "My nixos homelab";
2024-03-13 06:55:17 -05:00
inputs = {
# Nixpkgs and unstable
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
# nur
nur.url = "github:nix-community/NUR";
# nix-community hardware quirks
# https://github.com/nix-community
2024-03-18 16:16:39 -05:00
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
# home-manager - home user+dotfile manager
# https://github.com/nix-community/home-manager
2024-03-18 16:16:39 -05:00
home-manager = {
url = "github:nix-community/home-manager/release-23.11";
inputs.nixpkgs.follows = "nixpkgs";
};
2024-03-13 06:55:17 -05:00
# sops-nix - secrets with mozilla sops
# https://github.com/Mic92/sops-nix
2024-03-13 06:55:17 -05:00
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
# deploy-rs - Remote deployment
# https://github.com/serokell/deploy-rs
2024-03-18 16:16:39 -05:00
deploy-rs = {
url = "github:serokell/deploy-rs";
inputs.nixpkgs.follows = "nixpkgs";
};
2024-03-13 06:55:17 -05:00
# VSCode community extensions
# https://github.com/nix-community/nix-vscode-extensions
2024-03-13 06:55:17 -05:00
nix-vscode-extensions = {
url = "github:nix-community/nix-vscode-extensions";
inputs.nixpkgs.follows = "nixpkgs";
};
# nix-index database
# https://github.com/nix-community/nix-index-database
nix-index-database = {
url = "github:nix-community/nix-index-database";
inputs.nixpkgs.follows = "nixpkgs";
};
2024-03-13 06:55:17 -05:00
};
2024-03-18 04:26:02 -05:00
outputs =
{ self
, nixpkgs
, sops-nix
, deploy-rs
, home-manager
, nix-vscode-extensions
2024-03-18 04:26:02 -05:00
, ...
} @ inputs:
2024-03-24 02:34:14 -05:00
2024-03-18 04:26:02 -05:00
let
inherit (self) outputs;
forAllSystems = nixpkgs.lib.genAttrs [
"aarch64-linux"
"x86_64-linux"
];
2024-03-18 04:26:02 -05:00
in
{
2024-03-13 06:55:17 -05:00
# Use nixpkgs-fmt for 'nix fmt'
2024-03-18 04:06:00 -05:00
formatter = forAllSystems (system: nixpkgs.legacyPackages."${system}".nixpkgs-fmt);
2024-03-13 06:55:17 -05:00
# setup devshells against shell.nix
devShells = forAllSystems (pkgs: import ./shell.nix { inherit pkgs; });
2024-03-18 16:16:39 -05:00
nixosConfigurations =
# with self.lib;
2024-03-18 16:16:39 -05:00
let
specialArgs = {
inherit inputs outputs;
};
# Import overlays for building nixosconfig with them.
overlays = import ./nixos/overlays { inherit inputs; };
2024-03-23 04:45:09 -05:00
# generate a base nixos configuration with the
# specified overlays, hardware modules, and any extraModules applied
mkNixosConfig =
{ hostname
, system ? "x86_64-linux"
, nixpkgs ? inputs.nixpkgs
2024-03-24 07:21:13 -05:00
, hardwareModules ? [ ]
# basemodules is the base of the entire machine building
# here we import all the modules and setup home-manager
2024-03-23 04:45:09 -05:00
, baseModules ? [
sops-nix.nixosModules.sops
home-manager.nixosModules.home-manager
./nixos/profiles/global.nix # all machines get a global profile
./nixos/modules/nixos # all machines get nixos modules
./nixos/hosts/${hostname} # load this host's config folder for machine-specific config
{
home-manager = {
useUserPackages = true;
useGlobalPkgs = true;
extraSpecialArgs = {
inherit inputs hostname system;
};
};
}
2024-03-23 04:45:09 -05:00
]
2024-03-24 17:23:35 -05:00
, profileModules ? [ ]
2024-03-23 04:45:09 -05:00
}:
nixpkgs.lib.nixosSystem {
inherit system;
2024-03-24 17:23:35 -05:00
modules = baseModules ++ hardwareModules ++ profileModules;
2024-03-23 04:45:09 -05:00
specialArgs = { inherit self inputs nixpkgs; };
# Add our overlays
pkgs = import nixpkgs {
inherit system;
overlays = builtins.attrValues overlays;
config = {
allowUnfree = true;
allowUnfreePredicate = _: true;
};
};
2024-03-23 04:45:09 -05:00
};
2024-03-18 16:16:39 -05:00
in
rec {
2024-03-23 04:45:09 -05:00
"rickenbacker" = mkNixosConfig {
2024-03-25 07:37:21 -05:00
# NixOS laptop (dualboot windows, dunno why i kept it)
2024-03-23 04:45:09 -05:00
hostname = "rickenbacker";
2024-03-21 06:59:23 -05:00
system = "x86_64-linux";
2024-03-23 04:45:09 -05:00
hardwareModules = [
2024-03-24 07:21:13 -05:00
./nixos/profiles/hw-thinkpad-e14-amd.nix
inputs.nixos-hardware.nixosModules.lenovo-thinkpad-e14-amd
2024-03-21 06:59:23 -05:00
];
2024-03-24 17:23:35 -05:00
profileModules = [
./nixos/profiles/role-worstation.nix
2024-03-31 05:40:11 -05:00
{ home-manager.users.truxnell = ./nixos/home/truxnell/workstation.nix; }
2024-03-24 17:23:35 -05:00
];
2024-03-21 06:59:23 -05:00
};
2024-03-23 04:45:09 -05:00
"citadel" = mkNixosConfig {
2024-03-25 07:37:21 -05:00
# Gaming PC (dualboot windows)
2024-03-23 04:45:09 -05:00
hostname = "citadel";
system = "x86_64-linux";
2024-03-24 21:56:47 -05:00
hardwareModules = [
./nixos/profiles/hw-gaming-desktop.nix
];
profileModules = [
./nixos/profiles/role-worstation.nix
2024-03-31 05:40:11 -05:00
{ home-manager.users.truxnell = ./nixos/home/truxnell/workstation.nix; }
2024-03-24 21:56:47 -05:00
];
2024-03-23 04:45:09 -05:00
};
2024-03-24 07:21:13 -05:00
"dns01" = mkNixosConfig {
2024-03-25 07:37:21 -05:00
# Rpi for DNS and misc services
2024-03-24 07:21:13 -05:00
hostname = "dns01";
2024-03-25 07:37:21 -05:00
system = "aarch64-linux";
hardwareModules = [
./nixos/profiles/hw-rpi4.nix
inputs.nixos-hardware.nixosModules.raspberry-pi-4
];
profileModules = [
./nixos/profiles/role-server.nix
2024-03-31 05:40:11 -05:00
{ home-manager.users.truxnell = ./nixos/home/truxnell/server.nix; }
2024-03-25 07:37:21 -05:00
];
2024-03-19 06:51:31 -05:00
};
"dns02" = mkNixosConfig {
# Rpi for DNS and misc services
hostname = "dns02";
system = "aarch64-linux";
hardwareModules = [
./nixos/profiles/hw-rpi4.nix
inputs.nixos-hardware.nixosModules.raspberry-pi-4
];
profileModules = [
./nixos/profiles/role-server.nix
2024-03-31 05:40:11 -05:00
{ home-manager.users.truxnell = ./nixos/home/truxnell/server.nix; }
];
};
2024-03-24 07:21:13 -05:00
"durandal" = mkNixosConfig {
# test lenovo tiny
hostname = "durandal";
system = "x86_64-linux";
hardwareModules = [
./nixos/profiles/hw-generic-x86.nix
];
profileModules = [
./nixos/profiles/role-server.nix
{ home-manager.users.truxnell = ./nixos/home/truxnell/server.nix; }
];
};
2024-04-10 09:16:11 -05:00
"daedalus" = mkNixosConfig {
# lenovo tiny NAS
2024-04-10 09:16:11 -05:00
hostname = "daedalus";
system = "x86_64-linux";
hardwareModules = [
./nixos/profiles/hw-generic-x86.nix
];
profileModules = [
./nixos/profiles/role-server.nix
{ home-manager.users.truxnell = ./nixos/home/truxnell/server.nix; }
];
};
2024-03-18 16:16:39 -05:00
};
# # nix build .#images.rpi4
# rpi4 = nixpkgs.lib.nixosSystem {
# inherit specialArgs;
# modules = defaultModules ++ [
# "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
# ./nixos/hosts/images/sd-image
# ];
# };
# # nix build .#images.iso
# iso = nixpkgs.lib.nixosSystem {
# inherit specialArgs;
# modules = defaultModules ++ [
# "${nixpkgs}/nixos/modules/installer/cd-dvd/channel.nix"
# "${nixpkgs}/nixos/modules/installer/cd-dvd/iso-image.nix"
# ./nixos/hosts/images/cd-dvd
# ];
# };
2024-03-20 17:16:30 -05:00
# simple shortcut to allow for easier referencing of correct
# key for building images
# > nix build .#images.rpi4
2024-03-24 07:21:13 -05:00
# images.rpi4 = nixosConfigurations.rpi4.config.system.build.sdImage;
# images.iso = nixosConfigurations.iso.config.system.build.isoImage;
2024-03-20 17:16:30 -05:00
# deploy-rs
deploy.nodes =
let
mkDeployConfig = hostname: configuration: {
inherit hostname;
profiles.system =
let
inherit (configuration.config.nixpkgs.hostPlatform) system;
in
{
2024-03-24 02:34:14 -05:00
path = inputs.deploy-rs.lib."${system}".activate.nixos configuration;
2024-03-20 17:16:30 -05:00
sshUser = "truxnell";
user = "root";
sshOpts = [ "-t" ];
autoRollback = false;
magicRollback = true;
};
};
in
{
dns01 = mkDeployConfig "dns01" self.nixosConfigurations.dns01;
dns02 = mkDeployConfig "dns02" self.nixosConfigurations.dns02;
2024-03-25 00:47:43 -05:00
2024-03-20 17:16:30 -05:00
# dns02 = mkDeployConfig "dns02.natallan.com" self.nixosConfigurations.dns02;
};
# deploy-rs: This is highly advised, and will prevent many possible mistakes
2024-03-26 07:26:32 -05:00
checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) inputs.deploy-rs.lib;
2024-03-26 07:11:49 -05:00
# Convenience output that aggregates the outputs for home, nixos.
2024-03-26 07:11:49 -05:00
# Also used in ci to build targets generally.
top =
let
nixtop = nixpkgs.lib.genAttrs
(builtins.attrNames inputs.self.nixosConfigurations)
(attr: inputs.self.nixosConfigurations.${attr}.config.system.build.toplevel);
in
nixtop;
2024-03-16 07:46:36 -05:00
};
2024-03-18 16:16:39 -05:00
2024-03-16 07:46:36 -05:00
}