Files
dotfiles/flake.nix
T

321 lines
9.6 KiB
Nix
Raw Normal View History

2022-04-26 21:36:16 -04:00
{
2025-02-03 17:30:32 -05:00
description = "An opinionated flake containing the NixOS, nix-darwin, and home-manager configurations for multiple systems.";
2022-04-26 21:36:16 -04:00
2022-05-08 16:02:13 -04:00
# Other flakes that we want to pull from
2022-04-26 21:36:16 -04:00
inputs = {
2022-05-08 16:02:13 -04:00
# Used for system packages
2022-04-26 21:36:16 -04:00
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
2022-05-08 16:02:13 -04:00
# Used for specific stable packages
2026-05-30 12:54:34 -04:00
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-26.05";
2022-06-12 17:46:26 -04:00
# Used for MacOS system config
darwin = {
url = "github:lnl7/nix-darwin/master";
2022-06-12 17:46:26 -04:00
inputs.nixpkgs.follows = "nixpkgs";
};
2022-07-08 01:31:00 +00:00
# Used for Windows Subsystem for Linux compatibility
2024-01-07 08:51:21 -05:00
wsl = {
url = "github:nix-community/NixOS-WSL";
inputs.nixpkgs.follows = "nixpkgs";
};
2022-07-08 01:31:00 +00:00
2023-03-08 18:19:51 -05:00
# Used for user packages and dotfiles
2022-04-26 21:36:16 -04:00
home-manager = {
url = "github:nix-community/home-manager/master";
2024-04-14 08:08:57 -04:00
inputs.nixpkgs.follows = "nixpkgs"; # Use system packages list for their inputs
2022-04-26 21:36:16 -04:00
};
2022-05-08 16:02:13 -04:00
# Community packages; used for Firefox extensions
2025-02-03 17:30:32 -05:00
nur = {
url = "github:nix-community/nur";
inputs.nixpkgs.follows = "nixpkgs";
};
2022-04-26 21:36:16 -04:00
2024-06-18 18:22:05 -06:00
# Better App install management in macOS
mac-app-util = {
url = "github:hraban/mac-app-util";
2026-02-08 22:34:56 -05:00
# inputs.nixpkgs.follows = "nixpkgs"; # Use system packages list for their inputs
2024-06-18 18:22:05 -06:00
};
2026-07-21 13:55:42 +00:00
# Caddy with decoupled plugin hashes
nix-caddy-withplugins = {
url = "github:MichailiK/nix-caddy-withplugins/nixos-unstable";
# Important: Do not follow nixpkgs here, per the README
};
# Manage disk format and partitioning
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
2022-09-20 04:01:45 +00:00
# Used to generate NixOS images for other platforms
nixos-generators = {
url = "github:nix-community/nixos-generators";
inputs.nixpkgs.follows = "nixpkgs";
};
2026-03-15 09:48:27 -05:00
nix-index-database = {
url = "github:nix-community/nix-index-database";
inputs.nixpkgs.follows = "nixpkgs";
};
2022-11-27 12:29:45 -07:00
# Convert Nix to Neovim config
nix2vim = {
url = "github:gytis-ivaskevicius/nix2vim";
inputs.nixpkgs.follows = "nixpkgs";
};
2023-08-02 11:51:11 -04:00
# MPV Scripts
zenyd-mpv-scripts = {
url = "github:zenyd/mpv-scripts";
flake = false;
};
2025-11-02 17:01:34 -05:00
rust-overlay = {
url = "github:oxalica/rust-overlay";
};
2025-03-23 10:10:52 -04:00
# Zellij Switcher
zellij-switch = {
url = "github:mostafaqanbaryan/zellij-switch";
inputs.nixpkgs.follows = "nixpkgs";
2025-11-02 17:01:34 -05:00
inputs.rust-overlay.follows = "rust-overlay";
2025-03-23 10:10:52 -04:00
};
# Generic self-hosted REST API service
api = {
url = "github:nmasur/api";
inputs.nixpkgs.follows = "nixpkgs";
};
2025-10-29 12:03:20 -04:00
# # Text editor
# helix = {
# url = "github:helix-editor/helix";
# inputs.nixpkgs.follows = "nixpkgs";
# inputs.rust-overlay.follows = "rust-overlay";
# };
2025-03-30 11:00:21 -04:00
# # Nextcloud Apps
# nextcloud-news = {
# # https://github.com/nextcloud/news/releases
# url = "https://github.com/nextcloud/news/releases/download/25.0.0-alpha12/news.tar.gz";
# flake = false;
# };
# nextcloud-external = {
# # https://github.com/nextcloud-releases/external/releases
# url = "https://github.com/nextcloud-releases/external/releases/download/v5.5.2/external-v5.5.2.tar.gz";
# flake = false;
# };
# nextcloud-cookbook = {
# # https://github.com/christianlupus-nextcloud/cookbook-releases/releases/
# url = "https://github.com/christianlupus-nextcloud/cookbook-releases/releases/download/v0.11.2/cookbook-0.11.2.tar.gz";
# flake = false;
# };
# nextcloud-snappymail = {
# # https://github.com/the-djmaze/snappymail/releases
# # https://snappymail.eu/repository/nextcloud
# url = "https://snappymail.eu/repository/nextcloud/snappymail-2.38.2-nextcloud.tar.gz";
# # url = "https://github.com/nmasur/snappymail-nextcloud/releases/download/v2.36.3/snappymail-2.36.3-nextcloud.tar.gz";
# flake = false;
# };
2022-04-26 21:36:16 -04:00
};
2024-04-14 08:08:57 -04:00
outputs =
{ nixpkgs, ... }@inputs:
2022-05-15 20:46:17 -04:00
2022-04-26 21:36:16 -04:00
let
hostnames =
2024-04-14 08:08:57 -04:00
let
baseName = "masu.rs";
in
{
api = "api.${baseName}";
audiobooks = "read.${baseName}";
2026-09-05 21:24:01 +00:00
auth = "auth.${baseName}";
2025-05-12 03:07:38 +00:00
bookmarks = "keep.${baseName}";
books = "books.${baseName}";
budget = "money.${baseName}";
2025-09-17 03:35:20 +00:00
contacts = "contacts.${baseName}";
content = "cloud.${baseName}";
download = "download.${baseName}";
files = "files.${baseName}";
git = "git.${baseName}";
2026-09-05 15:33:24 +00:00
hister = "hister.${baseName}";
imap = "imap.purelymail.com";
influxdb = "influxdb.${baseName}";
irc = "irc.${baseName}";
mail = "noahmasur.com";
2025-05-05 20:36:27 +00:00
mathesar = "mathesar.${baseName}";
metrics = "metrics.${baseName}";
minecraft = "minecraft.${baseName}";
mumble = "mumble.${baseName}";
n8n = "n8n.${baseName}";
2025-07-14 21:45:08 -06:00
navidrome = "music.${baseName}";
notifications = "ntfy.${baseName}";
paperless = "paper.${baseName}";
photos = "photos.${baseName}";
postgresql = "pg.${baseName}";
prometheus = "prom.${baseName}";
2025-11-11 04:00:51 +00:00
recipes = "cooking.${baseName}";
secrets = "vault.${baseName}";
smtp = "smtp.purelymail.com";
status = "status.${baseName}";
stream = "stream.${baseName}";
transmission = "transmission.${baseName}";
2023-07-07 10:16:07 -06:00
};
2022-05-08 16:02:13 -04:00
lib = import ./lib inputs;
2025-03-30 11:00:21 -04:00
flattenAttrset = attrs: builtins.foldl' lib.mergeAttrs { } (builtins.attrValues attrs);
2025-03-12 01:51:12 +00:00
2025-03-30 12:35:15 -04:00
homeModules = builtins.mapAttrs (
system: hosts:
2025-03-12 01:51:12 +00:00
builtins.mapAttrs (
2025-03-30 12:35:15 -04:00
name: module: (builtins.head (lib.attrsToList module.home-manager.users)).value
) hosts
) lib.hosts;
2025-03-12 01:51:12 +00:00
2023-03-08 18:19:51 -05:00
# Disk formatting, only used once
2024-04-14 08:08:57 -04:00
diskoConfigurations = {
2025-03-11 02:31:22 +00:00
root = import ./hosts/x86_64-linux/swan/root.nix;
2023-04-16 16:33:16 -04:00
};
2022-10-18 12:21:22 +00:00
2025-03-14 00:13:56 +00:00
generators = builtins.mapAttrs (
# x86_64-linux = { arrow = ...; swan = ...; }
2025-03-14 00:13:56 +00:00
system: hosts:
(lib.concatMapAttrs (name: module: {
"${name}-aws" = lib.generateImage {
2025-03-14 00:13:56 +00:00
inherit system module;
format = "amazon";
specialArgs = { inherit hostnames; };
2025-03-14 00:13:56 +00:00
};
"${name}-iso" = lib.generateImage {
2025-03-14 00:13:56 +00:00
inherit system module;
format = "iso";
specialArgs = { inherit hostnames; };
2025-03-14 00:13:56 +00:00
};
2025-06-28 15:31:17 -04:00
"${name}-qcow" = lib.generateImage {
inherit system module;
format = "qcow-efi";
2025-06-28 15:31:17 -04:00
specialArgs = { inherit hostnames; };
# extraModules = [ "${nixpkgs}/nixos/modules/virtualisation/oci-image.nix" ];
2025-06-28 15:31:17 -04:00
};
}) hosts)
) lib.linuxHosts # x86_64-linux = { arrow = ...; swan = ...; }
;
2026-08-01 08:35:08 -04:00
in
{
inherit lib;
nixosConfigurations = flattenAttrset (
builtins.mapAttrs (
system: hosts:
builtins.mapAttrs (
name: module:
lib.buildNixos {
inherit system module;
specialArgs = { inherit hostnames; };
}
) hosts
) lib.linuxHosts
);
darwinConfigurations = flattenAttrset (
builtins.mapAttrs (
system: hosts:
builtins.mapAttrs (
name: module:
lib.buildDarwin {
inherit system module;
specialArgs = { inherit hostnames; };
}
) hosts
) lib.darwinHosts
);
homeConfigurations = flattenAttrset (
builtins.mapAttrs (
system: hosts:
builtins.mapAttrs (
name: module:
lib.buildHome {
inherit system module;
specialArgs = { inherit hostnames; };
}
) hosts
) homeModules
);
# packages =
# lib.forSystems lib.linuxSystems (
# system: generateImagesForHosts system // lib.pkgsBySystem.${system}.nmasur
# )
# // lib.forSystems lib.darwinSystems (system: lib.pkgsBySystem.${system}.nmasur);
2025-03-14 00:13:56 +00:00
packages = lib.forAllSystems (
system:
# Share the custom packages that I have placed under the nmasur namespace
lib.pkgsBySystem.${system}.nmasur
2025-03-14 00:13:56 +00:00
//
# Share generated images for each relevant host
2025-06-28 15:31:17 -04:00
(if (lib.hasInfix "linux" system) then generators.${system} else { })
# //
# # Oracle
# {
# flame-oci = nixosConfigurations.flame.config.system.build.OCIImage;
# }
2025-03-14 00:13:56 +00:00
);
2022-06-05 09:24:46 -04:00
2023-03-08 18:19:51 -05:00
# Development environments
2025-03-11 02:31:22 +00:00
devShells = lib.forAllSystems (system: {
default = lib.pkgsBySystem.${system}.nmasur.dotfiles-devshell;
2025-03-09 18:04:01 +00:00
});
2022-08-21 15:27:47 -06:00
# checks = lib.forAllSystems (
# system:
# let
# pkgs = import nixpkgs {
# inherit system;
# overlays = lib.overlays;
# };
# in
# {
# neovim =
# pkgs.runCommand "neovim-check-health" { buildInputs = [ inputs.self.packages.${system}.neovim ]; }
# ''
# mkdir -p $out
# export HOME=$TMPDIR
# nvim -c "checkhealth" -c "write $out/health.log" -c "quitall"
2022-04-27 09:23:26 -04:00
# # Check for errors inside the health log
# if $(grep "ERROR" $out/health.log); then
# cat $out/health.log
# exit 1
# fi
# '';
# }
# );
2023-07-29 15:20:14 -04:00
2025-03-11 02:31:22 +00:00
formatter = lib.forAllSystems (
2024-04-09 17:54:22 -04:00
system:
let
2025-03-11 02:31:22 +00:00
pkgs = import nixpkgs {
inherit system;
inherit (lib) overlays;
};
2024-04-09 17:54:22 -04:00
in
pkgs.nixfmt
2024-04-09 17:54:22 -04:00
);
2023-07-29 15:20:14 -04:00
2022-06-20 23:34:24 -04:00
# Templates for starting other projects quickly
templates = (import ./templates { inherit lib; });
2022-04-26 21:36:16 -04:00
};
}