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
Truxnell 36f866ea9c
chore: re-do home-manager (#42)
* docs: add better comments

* add deploy-rs

* wip

* hackz

* chore: make gc daily

* chore: add --fast for haxing

* fix: re-did home-manager

---------

Co-authored-by: Truxnell <9149206+truxnell@users.noreply.github.com>
2024-03-30 12:58:31 +00:00

256 lines
8 KiB
Nix

{
description = "My nixos homelab";
inputs = {
# Nixpkgs and unstable
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
# nix-community hardware quirks
# https://github.com/nix-community
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
# home-manager - home user+dotfile manager
# https://github.com/nix-community/home-manager
home-manager = {
url = "github:nix-community/home-manager/release-23.11";
inputs.nixpkgs.follows = "nixpkgs";
};
# sops-nix - secrets with mozilla sops
# https://github.com/Mic92/sops-nix
sops-nix = {
url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
# deploy-rs - Remote deployment
# https://github.com/serokell/deploy-rs
deploy-rs = {
url = "github:serokell/deploy-rs";
inputs.nixpkgs.follows = "nixpkgs";
};
# VSCode community extensions
# https://github.com/nix-community/nix-vscode-extensions
nix-vscode-extensions = {
url = "github:nix-community/nix-vscode-extensions";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{ self
, nixpkgs
, sops-nix
, home-manager
, ...
} @ inputs:
let
inherit (self) outputs;
forAllSystems = nixpkgs.lib.genAttrs [
"aarch64-linux"
"x86_64-linux"
];
in
rec {
# Use nixpkgs-fmt for 'nix fmt'
formatter = forAllSystems (system: nixpkgs.legacyPackages."${system}".nixpkgs-fmt);
nixosConfigurations =
# with self.lib;
let
specialArgs = {
inherit inputs outputs;
};
# Import overlays for building nixosconfig with them.
overlays = import ./nixos/overlays { inherit inputs; };
# generate a base nixos configuration with the
# specified overlays, hardware modules, and any extraModules applied
mkNixosConfig =
{ hostname
, system ? "x86_64-linux"
, nixpkgs ? inputs.nixpkgs
, hardwareModules ? [ ]
# basemodules is the base of the entire machine building
# here we import all the modules and setup home-manager
, 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
]
, profileModules ? [ ]
}:
nixpkgs.lib.nixosSystem {
inherit system;
modules = baseModules ++ hardwareModules ++ profileModules;
specialArgs = { inherit self inputs nixpkgs; };
# Add our overlays
pkgs = import nixpkgs {
inherit system;
overlays = builtins.attrValues overlays;
config = {
allowUnfree = true;
allowUnfreePredicate = _: true;
};
};
};
in
{
"rickenbacker" = mkNixosConfig {
# NixOS laptop (dualboot windows, dunno why i kept it)
hostname = "rickenbacker";
system = "x86_64-linux";
hardwareModules = [
./nixos/profiles/hw-thinkpad-e14-amd.nix
inputs.nixos-hardware.nixosModules.lenovo-thinkpad-e14-amd
];
profileModules = [
./nixos/profiles/role-worstation.nix
];
};
"citadel" = mkNixosConfig {
# Gaming PC (dualboot windows)
hostname = "citadel";
system = "x86_64-linux";
hardwareModules = [
./nixos/profiles/hw-gaming-desktop.nix
];
profileModules = [
./nixos/profiles/role-worstation.nix
];
};
"dns01" = mkNixosConfig {
# Rpi for DNS and misc services
hostname = "dns01";
system = "aarch64-linux";
hardwareModules = [
./nixos/profiles/hw-rpi4.nix
inputs.nixos-hardware.nixosModules.raspberry-pi-4
];
profileModules = [
./nixos/profiles/role-server.nix
];
};
"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
];
};
};
homeConfigurations = {
# For servers (no gui)
server = { pkgs, lib, username, ... }: {
imports = [
./nixos/home/profiles/global.nix
./nixos/home/profiles/server.nix
./nixos/home/modules
];
};
# For workstations (X11 + awesome)
desktop = { pkgs, lib, username, ... }: {
imports = [
./nixos/home/profiles/global.nix
./nixos/home/profiles/workstation.nix
./nixos/home/modules
];
};
# # 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
# ];
# };
};
# simple shortcut to allow for easier referencing of correct
# key for building images
# > nix build .#images.rpi4
# images.rpi4 = nixosConfigurations.rpi4.config.system.build.sdImage;
# images.iso = nixosConfigurations.iso.config.system.build.isoImage;
# deploy-rs
deploy.nodes =
let
mkDeployConfig = hostname: configuration: {
inherit hostname;
profiles.system =
let
inherit (configuration.config.nixpkgs.hostPlatform) system;
in
{
path = inputs.deploy-rs.lib."${system}".activate.nixos configuration;
sshUser = "truxnell";
user = "root";
sshOpts = [ "-t" ];
autoRollback = false;
magicRollback = true;
};
};
in
{
rickenbacker = mkDeployConfig "rickenbacker" self.nixosConfigurations.rickenbacker;
dns01 = mkDeployConfig "10.8.10.11" self.nixosConfigurations.dns01;
dns02 = mkDeployConfig "10.8.10.10" self.nixosConfigurations.dns02;
# dns02 = mkDeployConfig "dns02.natallan.com" self.nixosConfigurations.dns02;
};
# deploy-rs: This is highly advised, and will prevent many possible mistakes
checks = builtins.mapAttrs (system: deployLib: deployLib.deployChecks self.deploy) inputs.deploy-rs.lib;
# Convenience output that aggregates the outputs for home, nixos.
# 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);
hometop = nixpkgs.lib.genAttrs
(builtins.attrNames inputs.self.homeConfigurations)
(attr: inputs.self.homeManagerConfigurations.${attr}.activationPackage);
in
nixtop // hometop;
};
}