aboutsummaryrefslogblamecommitdiff
path: root/flake.nix
blob: 83aad4156f9cde00e677b7146b8525836b01ef8c (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";
    };

    flake-utils.url = "github:numtide/flake-utils";

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

    devshell = {
      url = "github:numtide/devshell";
      inputs.nixpkgs.follows = "nixpkgs";
    };

  };

  # Output config, or config for NixOS system
  outputs =
    {
      self,
      nixpkgs,
      darwin,
      flake-utils,
      pre-commit-hooks,
      devshell,
      treefmt-nix,

      ...
    }@inputs:
    flake-utils.lib.eachDefaultSystem (
      system:
      let
        pkgs = import nixpkgs {
          inherit system;
          overlays = [ devshell.overlays.default ];
        };
        treefmt = (
          treefmt-nix.lib.mkWrapper pkgs {
            projectRootFile = "flake.nix";
            programs = {
              nixfmt.enable = true;
              actionlint.enable = true;
              deadnix.enable = true;
              just.enable = true;
            };
          }
        );
      in
      {
        checks = {
          pre-commit-check = pre-commit-hooks.lib.${system}.run {
            src = ./.;
            hooks = {
              check-merge-conflicts.enable = true;
              end-of-file-fixer.enable = true;
              treefmt-check = {
                enable = true;
                entry = "${treefmt}/bin/treefmt --fail-on-change";
                pass_filenames = false;
              };
            };
          };
        };

        formatter = treefmt;

        devShells.default = pkgs.devshell.mkShell {
          packages = with pkgs; [
            just

            treefmt

          ];
          devshell.startup.pre-commit.text = self.checks.${system}.pre-commit-check.shellHook;
          env = [
            {
              name = "DEVSHELL_NO_MOTD";
              value = "1";
            }
          ];
        };

      }
    )
    // (flake-utils.lib.eachDefaultSystemPassThrough (
      system:
      let
        mkSystem = import ./nix/lib/mkSystem.nix { inherit nixpkgs inputs; };
      in
      {

        # a VM running on the MacBook Air
        nixosConfigurations.vm-aarch64 = mkSystem "vm-aarch64" {
          system = "aarch64-linux";
          user = "fcuny";
        };

        # a VM running on the synology DS923+
        nixosConfigurations.vm-synology = mkSystem "vm-synology" {
          system = "x86_64-linux";
          user = "fcuny";
        };

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

        # my work MacBook Pro
        darwinConfigurations.hq-c02fk3q7md6t = mkSystem "hq-c02fk3q7md6t" {
          system = "x86_64-darwin";
          user = "fcuny";
          darwin = true;
        };
      }
    ));
}