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

                                                
 
            
                                                     
 
                    
                                                              
                                         
      
 
              
                                                      


                                         



                                         
 
                        
                                          

                                         
    
 
                                             

           

              
                  
                       

             









                                                                           
          




















                                                                             
              
                                                   

            
        
 





                                                       
 





                                                                     
 




















                                                                                                  
 
{
  description = "personal NixOS configurations";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";

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

    darwin = {
      url = "github:lnl7/nix-darwin/nix-darwin-24.11";
      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";
    };
  };

  # Output config, or config for NixOS system
  outputs =
    {
      nixpkgs,
      darwin,
      treefmt-nix,
      pre-commit-hooks,
      ...
    }@inputs:
    let
      system = "aarch64-darwin";
      pkgs = import nixpkgs { inherit system; };
      mkSystem = import ./nix/lib/mkSystem.nix { inherit nixpkgs inputs; };
      treefmtEval = treefmt-nix.lib.evalModule pkgs {
        projectRootFile = "flake.nix";
        programs = {
          nixfmt.enable = true;
          actionlint.enable = true;
          deadnix.enable = true;
        };
      };
    in
    {
      # nix fmt
      formatter.${system} = treefmtEval.config.build.wrapper;

      # nix flake check
      checks.${system} = {
        pre-commit-check = inputs.pre-commit-hooks.lib.${pkgs.system}.run {
          src = ./.;
          hooks = {
            actionlint.enable = true;
            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;
            treefmt = {
              enable = true;
              entry = "${treefmtEval.config.build.wrapper}/bin/treefmt --ci";
            };
            trim-trailing-whitespace.enable = true;
          };
        };
      };

      # my personal MacBook Air
      darwinConfigurations.mba-m2 = mkSystem "mba-m2" {
        system = "aarch64-darwin";
        user = "fcuny";
        darwin = true;
      };

      # work laptop
      darwinConfigurations.hq-kwny2vh41p = mkSystem "hq-kwny2vh41p" {
        system = "aarch64-darwin";
        user = "fcuny";
        darwin = true;
      };

      devShells.${system}.default = pkgs.mkShellNoCC {
        packages = with pkgs; [
          git
          (writeScriptBin "build" ''
            set -e
            echo "> Running darwin-rebuild switch..."
            ${inputs.darwin.packages.${system}.darwin-rebuild}/bin/darwin-rebuild build --flake .
            echo "> darwin-rebuild build was successful ✅"
            echo "> macOS config was successfully applied 🚀"
          '')
          (writeScriptBin "switch" ''
            set -e
            echo "> Running darwin-rebuild switch..."
            ${inputs.darwin.packages.${system}.darwin-rebuild}/bin/darwin-rebuild switch --flake .
            echo "> darwin-rebuild build was successful ✅"
            echo "> macOS config was successfully applied 🚀"
          '')
          (writeScriptBin "update-deps" "nix flake update --commit-lock-file")
        ];
      };
    };
}