aboutsummaryrefslogblamecommitdiff
path: root/flake.nix
blob: ec2f0775ab4c5a7489a2766c71c8d64bcde093a5 (plain) (tree)
1
2
3
4
5
6
7
8
9

                                                
 
            
                                                                           
 
                    
                                                              
                                         
      
 
              
                                                      


                                         




                                         

                                                 

      




                                         



                                         
 
                        
                                          

                                         




                                                 
 

                                       


                                         
                                                     
    
 
           















                          



                        



























                                                            
        












                                               
                                              


                                    
                                         


                                    
                                             


                                    
                                        




                                      
                                           


                                      
                                                  

































































                                                                                                            
                                 


                                
          
                                                                            
        

                              


                                
          


                                                                                               

        
                                 



                                
                            



                                                                 







                                                
                                                     

                              
                                                                                               
                



              



                                                           
                            
                                               


                           

              

         
      
 
{
  description = "personal NixOS configurations";

  inputs = {
    nixpkgs.url = "https://channels.nixos.org/nixos-25.11/nixexprs.tar.xz";

    home-manager = {
      url = "github:nix-community/home-manager/release-25.11";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    darwin = {
      url = "github:lnl7/nix-darwin/nix-darwin-25.11";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    disko = {
      url = "github:nix-community/disko";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    nixos-hardware = {
      url = "github:NixOS/nixos-hardware/master";
    };

    agenix = {
      url = "github:ryantm/agenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    treefmt-nix = {
      url = "github:numtide/treefmt-nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    pre-commit-hooks = {
      url = "github:cachix/git-hooks.nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    emacs-overlay = {
      url = "github:nix-community/emacs-overlay";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    nur = {
      url = "github:nix-community/NUR";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    my-go-tools.url = "git+https://code.fcuny.net/x";
  };

  outputs =
    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"
      ];

      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/rivendell.nix;
          };
          bree = {
            system = "x86_64-linux";
            config = ./machines/bree.nix;
          };
          argonath = {
            system = "x86_64-linux";
            config = ./machines/argonath.nix;
          };
          iso = {
            system = "x86_64-linux";
            config = ./machines/iso.nix;
          };
        };
        darwin = {
          mba-m2 = {
            system = "aarch64-darwin";
            config = ./machines/mba-m2.nix;
          };
          HQ-KWNY2VH41P = {
            system = "aarch64-darwin";
            config = ./machines/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 { };
      };

      formatter = forAllSystems (
        system:
        let
          pkgs = pkgsFor system;
        in
        (treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build.wrapper
      );

      checks = forAllSystems (
        system:
        let
          pkgs = pkgsFor system;
        in
        {
          formatting = (treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build.check self;
        }
      );

      devShells = forAllSystems (
        system:
        let
          pkgs = pkgsFor system;

          # Pre-commit hooks
          pre-commit-check = pre-commit-hooks.lib.${system}.run {
            src = ./.;
            hooks = {
              check-merge-conflicts.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;
              trim-trailing-whitespace.enable = true;
              treefmt = {
                enable = true;
                package = (treefmt-nix.lib.evalModule pkgs ./treefmt.nix).config.build.wrapper;
              };
            };
          };
        in
        {
          default = pkgs.mkShellNoCC {
            inherit (pre-commit-check) shellHook;
            buildInputs = pre-commit-check.enabledPackages;
            packages = with pkgs; [
              _1password-cli
              agenix.packages.${system}.default
              git
              just
              nixos-rebuild
            ];
          };
        }
      );
    };
}