infra/flake.nix

252 lines
8.3 KiB
Nix
Raw Normal View History

2022-10-29 17:37:47 +01:00
{
description = "Nix flake for my infrastructure";
inputs = {
2023-10-08 22:54:52 +01:00
agenix.url = "github:ryantm/agenix?rev=1f677b3e161d3bdbfd08a939e8f25de2568e0ef4";
2023-09-08 11:26:32 +01:00
terranix.url = "github:terranix/terranix";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixinate.url = "github:matthewcroughan/nixinate";
2023-10-08 22:54:52 +01:00
nixpkgs-wayland = {
url = "github:nix-community/nixpkgs-wayland";
inputs.nixpkgs.follows = "nixpkgs";
};
2023-09-09 22:53:50 +01:00
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
alertmanager-ntfy.url = "github:alexbakker/alertmanager-ntfy";
2023-10-19 12:47:18 +01:00
kubenix.url = "github:hall/kubenix";
2022-11-26 10:41:40 +00:00
};
2022-10-29 17:37:47 +01:00
2023-10-19 12:47:18 +01:00
outputs = { self, nixpkgs, nixos-generators, nixinate, home-manager, agenix, terranix, alertmanager-ntfy, nixpkgs-wayland, kubenix }@inputs:
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
2023-09-08 11:26:32 +01:00
tf = terranix.lib.terranixConfiguration {
system = "x86_64-linux";
modules = [ ./terraform/main.nix ];
};
2022-10-29 17:37:47 +01:00
in {
devShells.x86_64-linux.default = with pkgs; mkShell {
2022-12-16 17:42:21 +00:00
shellHook =
''
set -o allexport
source .env set
set +o allexport
2022-12-16 17:42:21 +00:00
'';
2022-10-29 17:37:47 +01:00
nativeBuildInputs = [
2023-11-30 12:09:51 +00:00
jq opentofu kubectl
k9s terraform-ls kubernetes-helm
nil
2022-10-29 17:37:47 +01:00
];
buildInputs = [ ];
};
2022-11-26 10:41:40 +00:00
packages.aarch64-linux = {
2023-09-05 17:16:10 +01:00
raspberry-pi = nixos-generators.nixosGenerate {
2022-11-26 10:41:40 +00:00
system = "aarch64-linux";
modules = [
(nixpkgs + "/nixos/modules/installer/sd-card/sd-image-aarch64-installer.nix")
./pi-imgs/pi-initial.nix
2022-11-26 10:41:40 +00:00
];
format = "sd-aarch64-installer";
};
};
2023-10-19 12:47:18 +01:00
packages.x86_64-linux = {
kubernetes = (kubenix.evalModules.x86_64-linux {
module = { kubenix, ... }: {
2023-10-19 14:31:30 +01:00
imports = [
kubenix.modules.k8s ./homelab/kubernetes.nix
];
2023-10-19 12:47:18 +01:00
};
}).config.kubernetes.result;
};
2023-09-08 11:26:32 +01:00
apps = nixinate.nixinate.x86_64-linux self // {
x86_64-linux = {
2023-11-30 12:09:51 +00:00
kube-apply = {
type = "app";
program = toString (pkgs.writers.writeBash "diff" ''
${pkgs.kubectl}/bin/kubectl apply -f ${self.packages.x86_64-linux.kubernetes}
'');
};
2023-10-27 14:53:37 +01:00
kube-diff = {
type = "app";
program = toString (pkgs.writers.writeBash "diff" ''
${pkgs.kubectl}/bin/kubectl diff -f ${self.packages.x86_64-linux.kubernetes}
'');
};
2023-09-08 11:26:32 +01:00
tf-plan = {
type = "app";
program = toString (pkgs.writers.writeBash "plan" ''
if [[ -e terraform/config.tf.json ]]; then rm -f terraform/config.tf.json; fi
cp ${tf} terraform/config.tf.json \
2023-10-08 22:54:52 +01:00
&& ${pkgs.opentofu}/bin/tofu -chdir=terraform init \
&& ${pkgs.opentofu}/bin/tofu -chdir=terraform plan -out=plan.out
2023-09-08 11:26:32 +01:00
'');
};
tf-apply = {
type = "app";
program = toString (pkgs.writers.writeBash "apply" ''
if [[ -e terraform/config.tf.json ]]; then rm -f terraform/config.tf.json; fi
cp ${tf} terraform/config.tf.json \
2023-10-08 22:54:52 +01:00
&& ${pkgs.opentofu}/bin/tofu -chdir=terraform init \
&& ${pkgs.opentofu}/bin/tofu -chdir=terraform apply plan.out
2023-09-08 11:26:32 +01:00
'');
};
};
};
2023-09-06 10:52:40 +01:00
homeConfigurations."gsimmer" = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [ ./nix/london/gsimmer.nix ];
};
nixosConfigurations = {
london = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
2023-09-05 21:55:18 +01:00
(import ./nix/london/configuration.nix)
2023-09-07 19:11:04 +01:00
home-manager.nixosModules.home-manager
{
home-manager.useUserPackages = true;
home-manager.users.gsimmer = import ./nix/london/gsimmer.nix;
}
2023-10-08 22:54:52 +01:00
({pkgs, config, ... }:
{
config = {
nix.settings = {
# add binary caches
trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
"nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA="
];
substituters = [
"https://cache.nixos.org"
"https://nixpkgs-wayland.cachix.org"
];
};
# use it as an overlay
nixpkgs.overlays = [ nixpkgs-wayland.overlay ];
};
}
)
];
};
oracle-gitea-runner = nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
2023-09-05 21:55:18 +01:00
(import ./nix/oracle-gitea-runner/configuration.nix)
{
_module.args.nixinate = {
host = "143.47.229.209";
sshUser = "root";
buildOn = "remote";
substituteOnTarget = true;
hermetic = false;
};
}
];
};
2024-01-10 19:06:54 +00:00
oracle-stream = nixpkgs.lib.nixosSystem {
2023-10-30 12:26:56 +00:00
system = "aarch64-linux";
modules = [
2024-01-10 19:06:54 +00:00
(import ./nix/oracle-stream/configuration.nix)
2023-10-30 12:26:56 +00:00
{
_module.args.nixinate = {
2023-12-09 22:43:11 +00:00
host = "100.98.25.34";
2023-10-30 12:26:56 +00:00
sshUser = "root";
buildOn = "remote";
substituteOnTarget = true;
hermetic = false;
};
}
];
};
2023-09-05 17:08:43 +01:00
monitoring = nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
2023-09-05 17:08:43 +01:00
modules = [
2023-09-05 21:55:18 +01:00
(import ./nix/monitoring/configuration.nix)
2023-09-13 23:01:51 +01:00
agenix.nixosModules.default
alertmanager-ntfy.nixosModules.x86_64-linux.default
2023-09-05 17:08:43 +01:00
{
_module.args.nixinate = {
host = "monitoring";
sshUser = "root";
buildOn = "remote";
substituteOnTarget = true;
hermetic = false;
};
}
];
};
nas = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
2023-09-05 21:55:18 +01:00
(import ./nix/nas/configuration.nix)
2023-09-07 19:10:23 +01:00
agenix.nixosModules.default
home-manager.nixosModules.home-manager
{
2023-09-05 21:55:18 +01:00
home-manager.users.gsimmer = import ./nix/nas/home.nix;
_module.args.nixinate = {
host = "vancouver";
sshUser = "gsimmer";
buildOn = "remote";
substituteOnTarget = true;
hermetic = false;
};
}
];
};
2023-09-25 10:48:31 +01:00
seattle = nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
agenix.nixosModules.default
2023-09-25 10:48:31 +01:00
(import ./nix/seattle/configuration.nix)
{
_module.args.nixinate = {
host = "seattle";
sshUser = "gsimmer";
buildOn = "remote";
substituteOnTarget = true;
hermetic = false;
};
}
];
};
glasgow = nixpkgs.lib.nixosSystem {
system = "aarch64-linux";
modules = [
agenix.nixosModules.default
2023-09-25 10:48:31 +01:00
(import ./nix/glasgow/configuration.nix)
{
_module.args.nixinate = {
host = "glasgow";
sshUser = "gsimmer";
buildOn = "remote";
substituteOnTarget = true;
hermetic = false;
};
}
];
};
proxmox-k3s-node-1 = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
agenix.nixosModules.default
(import ./nix/proxmox-k3s-node/configuration.nix)
{
_module.args.nixinate = {
host = "proxmox-node-1";
sshUser = "gsimmer";
buildOn = "remote";
substituteOnTarget = true;
hermetic = false;
};
}
];
};
};
};
2022-10-29 17:37:47 +01:00
}