aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2025-12-13 17:05:13 -0800
committerFranck Cuny <franck@fcuny.net>2025-12-13 17:06:49 -0800
commit548f31ae7f81b4ef262b8ecee11918583eb87cd6 (patch)
tree643a5996f1b1d20c78c2f689ba4b1092f81e9584 /flake.nix
parentremove abstractions for managing users (diff)
downloadinfra-548f31ae7f81b4ef262b8ecee11918583eb87cd6.tar.gz
stop using flake-parts to simplify the setup
It's a lot of abstractions that are hard to fully understand, I don't need that complexity for my setup.
Diffstat (limited to '')
-rw-r--r--flake.nix268
1 files changed, 254 insertions, 14 deletions
diff --git a/flake.nix b/flake.nix
index 7a8b03a..2c000fc 100644
--- a/flake.nix
+++ b/flake.nix
@@ -48,28 +48,268 @@
inputs.nixpkgs.follows = "nixpkgs";
};
- flake-parts = {
- url = "github:hercules-ci/flake-parts";
- inputs.nixpkgs-lib.follows = "nixpkgs";
- };
-
my-go-tools.url = "git+https://code.fcuny.net/x";
};
outputs =
- inputs@{ flake-parts, ... }:
- flake-parts.lib.mkFlake { inherit inputs; } {
- systems = [
+ inputs@{
+ self,
+ nixpkgs,
+ darwin,
+ home-manager,
+ disko,
+ agenix,
+ treefmt-nix,
+ pre-commit-hooks,
+ emacs-overlay,
+ nur,
+ my-go-tools,
+ ...
+ }:
+ let
+ supportedSystems = [
"aarch64-darwin"
"x86_64-linux"
];
- imports = [
- ./flake/checks.nix
- ./flake/devshells.nix
- ./flake/formatter.nix
- ./flake/hosts.nix
- ./flake/overlays.nix
+ forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
+
+ pkgsFor =
+ system:
+ import nixpkgs {
+ inherit system;
+ config.allowUnfree = true;
+ overlays = [
+ self.overlays.default
+ agenix.overlays.default
+ emacs-overlay.overlay
+ nur.overlays.default
+ my-go-tools.overlays.default
+ ];
+ };
+
+ nixSettings = {
+ nix.registry.nixpkgs = {
+ flake = nixpkgs;
+ };
+ };
+
+ defaultModules = [
+ nixSettings
+ agenix.nixosModules.age
+ disko.nixosModules.disko
+ home-manager.nixosModules.home-manager
+ ./modules/default.nix
];
+
+ # Default modules for Darwin hosts
+ darwinDefaultModules = [
+ nixSettings
+ agenix.darwinModules.age
+ home-manager.darwinModules.home-manager
+ ./modules/default-darwin.nix
+ ];
+
+ machines = {
+ nixos = {
+ rivendell = {
+ system = "x86_64-linux";
+ config = ./machines/nixos/x86_64-linux/rivendell.nix;
+ };
+ bree = {
+ system = "x86_64-linux";
+ config = ./machines/nixos/x86_64-linux/bree.nix;
+ };
+ argonath = {
+ system = "x86_64-linux";
+ config = ./machines/nixos/x86_64-linux/argonath.nix;
+ };
+ iso = {
+ system = "x86_64-linux";
+ config = ./machines/nixos/x86_64-linux/iso.nix;
+ };
+ };
+ darwin = {
+ mba-m2 = {
+ system = "aarch64-darwin";
+ config = ./machines/darwin/aarch64-darwin/mba-m2.nix;
+ };
+ HQ-KWNY2VH41P = {
+ system = "aarch64-darwin";
+ config = ./machines/darwin/aarch64-darwin/HQ-KWNY2VH41P.nix;
+ };
+ };
+ };
+
+ nixosConfigurations = nixpkgs.lib.mapAttrs (
+ name: machine:
+ let
+ pkgs = pkgsFor machine.system;
+ in
+ nixpkgs.lib.nixosSystem {
+ inherit (machine) system;
+ specialArgs = {
+ hostName = name;
+ inherit self inputs;
+ hostConfigurations = nixpkgs.lib.mapAttrs (_: conf: conf.config) nixosConfigurations;
+ };
+ modules = [
+ {
+ system.configurationRevision = nixpkgs.lib.mkIf (self ? rev) self.rev;
+ system.nixos.versionSuffix = nixpkgs.lib.mkForce "git.${builtins.substring 0 11 nixpkgs.rev}";
+ nixpkgs.pkgs = pkgs;
+ environment.systemPackages = [ pkgs.git ];
+ }
+ ]
+ ++ defaultModules
+ ++ [
+ machine.config
+ my-go-tools.nixosModules.default
+ ];
+ }
+ ) machines.nixos;
+
+ darwinConfigurations = nixpkgs.lib.mapAttrs (
+ name: machine:
+ let
+ pkgs = pkgsFor machine.system;
+ in
+ darwin.lib.darwinSystem {
+ inherit (machine) system;
+ specialArgs = {
+ hostName = name;
+ inherit self inputs;
+ };
+ modules = [
+ {
+ nixpkgs.pkgs = pkgs;
+ nixpkgs.hostPlatform = machine.system;
+ system.stateVersion = 5;
+ environment.systemPackages = [ pkgs.git ];
+ }
+ ]
+ ++ darwinDefaultModules
+ ++ [ machine.config ];
+ }
+ ) machines.darwin;
+ in
+ {
+ # Host configurations
+ inherit nixosConfigurations darwinConfigurations;
+
+ # Overlays
+ overlays.default = _final: prev: {
+ sapi = prev.callPackage ./pkgs/sapi { };
+ hashi = prev.callPackage ./pkgs/hashi { };
+ };
+
+ devShells = forAllSystems (
+ system:
+ let
+ pkgs = pkgsFor system;
+
+ # Treefmt configuration
+ treefmtEval = treefmt-nix.lib.evalModule pkgs {
+ projectRootFile = "flake.nix";
+ programs = {
+ nixfmt.enable = true;
+ deadnix.enable = true;
+ };
+ };
+
+ # Pre-commit hooks
+ pre-commit-check = pre-commit-hooks.lib.${system}.run {
+ src = ./.;
+ hooks = {
+ check-merge-conflicts.enable = true;
+ deadnix.enable = true;
+ detect-private-keys.enable = true;
+ end-of-file-fixer.enable = true;
+ mixed-line-endings.enable = true;
+ shellcheck = {
+ enable = true;
+ excludes = [ "\\.envrc$" ];
+ };
+ flake-checker.enable = true;
+ treefmt = {
+ enable = true;
+ entry = "${treefmtEval.config.build.wrapper}/bin/treefmt --ci";
+ };
+ trim-trailing-whitespace.enable = true;
+ };
+ };
+
+ # Import any custom scripts
+ scripts = import ./flake/scripts {
+ inherit pkgs system inputs;
+ };
+ in
+ {
+ default = pkgs.mkShellNoCC {
+ inherit (pre-commit-check) shellHook;
+ packages =
+ with pkgs;
+ [
+ nixos-rebuild
+ git
+ agenix.packages."${system}".default
+ ]
+ ++ scripts.all;
+ };
+ }
+ );
+ formatter = forAllSystems (
+ system:
+ let
+ pkgs = pkgsFor system;
+ treefmtEval = treefmt-nix.lib.evalModule pkgs {
+ projectRootFile = "flake.nix";
+ programs = {
+ nixfmt.enable = true;
+ deadnix.enable = true;
+ };
+ };
+ in
+ treefmtEval.config.build.wrapper
+ );
+
+ checks = forAllSystems (
+ system:
+ let
+ pkgs = pkgsFor system;
+
+ treefmtEval = treefmt-nix.lib.evalModule pkgs {
+ projectRootFile = "flake.nix";
+ programs = {
+ nixfmt.enable = true;
+ deadnix.enable = true;
+ };
+ };
+
+ pre-commit-check = pre-commit-hooks.lib.${system}.run {
+ src = ./.;
+ hooks = {
+ check-merge-conflicts.enable = true;
+ deadnix.enable = true;
+ detect-private-keys.enable = true;
+ end-of-file-fixer.enable = true;
+ mixed-line-endings.enable = true;
+ shellcheck = {
+ enable = true;
+ excludes = [ "\\.envrc$" ];
+ };
+ flake-checker.enable = true;
+ treefmt = {
+ enable = true;
+ entry = "${treefmtEval.config.build.wrapper}/bin/treefmt --ci";
+ };
+ trim-trailing-whitespace.enable = true;
+ };
+ };
+ in
+ {
+ inherit pre-commit-check;
+ }
+ );
};
}