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

                                                
 
            
                                                       
                                                                   
 
                                              
 

                                                             




                                         

                                         
                    
                                                              


                                                                          
 




                                          









                                       


                                             
                                 
       










                                                        
      


                                        
          



                                                                          
                                       







                                                                                           
 























                                                                                             
 










                                                                              

              

















                                                                            









                                                                 
                             













                                                                   

        
 
{
  description = "personal NixOS configurations";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/release-22.05";
    nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";

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

    emacs-overlay.url = "github:nix-community/emacs-overlay";

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

    nur.url = "github:nix-community/NUR";

    home-manager = {
      url = "github:nix-community/home-manager/release-22.05";
      # We want home-manager to use the same set of nixpkgs as our system.
      inputs.nixpkgs.follows = "nixpkgs";
    };

    rust = {
      url = "github:oxalica/rust-overlay";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    pre-commit-hooks = {
      type = "github";
      owner = "cachix";
      repo = "pre-commit-hooks.nix";
      ref = "master";
      inputs = {
        flake-utils.follows = "futils";
        nixpkgs.follows = "nixpkgs";
      };
    };
  };

  # Output config, or config for NixOS system
  outputs = inputs@{ self, ... }:
    let
      myLib = import ./nix inputs;
      lib = inputs.nixpkgs.lib // builtins;
      supportedSystems = [ "x86_64-linux" ];
      forAllSystems = lib.genAttrs supportedSystems;

      # Nixpkgs instantiated for supported system types.
      nixpkgsFor = forAllSystems (system:
        import inputs.nixpkgs {
          inherit system;
          config = { allowUnfree = true; };
        });
    in
    {
      checks = forAllSystems (system:
        let pkgs = nixpkgsFor.${system};
        in
        {
          pre-commit-check = inputs.pre-commit-hooks.lib."${system}".run {
            src = ./.;
            hooks = {
              nix-linter.enable = true;
              nixpkgs-fmt.enable = true;
              terraform-format.enable = true;
              trailing-whitespace = {
                enable = true;
                entry =
                  "${pkgs.python3Packages.pre-commit-hooks}/bin/trailing-whitespace-fixer";
                types = [ "text" ];
              };

              end-of-file-fixer = {
                enable = true;
                entry =
                  "${pkgs.python3Packages.pre-commit-hooks}/bin/end-of-file-fixer";
                types = [ "text" ];
              };

              check-executables-have-shebangs = {
                entry =
                  "${pkgs.python3Packages.pre-commit-hooks}/check-executables-have-shebangs";
                types = [ "text" "executable" ];
              };

              check-json = {
                enable = true;
                entry = "${pkgs.python3Packages.pre-commit-hooks}/check-json";
                types = [ "json" ];
              };

              check-toml = {
                enable = true;
                entry = "${pkgs.python3Packages.pre-commit-hooks}/check-toml";
                types = [ "toml" ];
              };

              check-yaml = {
                enable = true;
                entry = "${pkgs.python3Packages.pre-commit-hooks}/check-yaml";
                types = [ "yaml" ];
              };

              shellcheck = {
                enable = true;
                files = "\\.sh$";
                types_or = [ "file" ];
              };
            };
          };
        });

      devShells = forAllSystems (system: {
        default = inputs.nixpkgs.legacyPackages.${system}.mkShell {
          name = "fcuny-configuration-on-${system}-system";
          buildInputs = with inputs.nixpkgs.legacyPackages.${system}.pkgs; [
            gitAndTools.pre-commit
            nixfmt
            nixpkgs-fmt
            rnix-lsp
            home-manager
            git
            nixos-rebuild
          ];
          inherit (self.checks.${system}.pre-commit-check) shellHook;
        };
      });

      packages = forAllSystems (system:
        let pkgs = nixpkgsFor.${system};
        in
        {
          inherit (inputs.futils.lib) filterPackages flattenTree;
          tools = import ./tools { inherit pkgs; };
          ops = import ./ops { inherit pkgs; };
          users.fcuny = import ./users/fcuny { inherit pkgs; };
        });

      nixosConfigurations = {
        aptos = myLib.mkSystem { hostname = "aptos"; };
        carmel = myLib.mkSystem { hostname = "carmel"; };
        tahoe = myLib.mkSystem { hostname = "tahoe"; };
      };

      homeConfigurations = {
        useGlobalPkgs = true;
        useUserPackages = true;

        "fcuny@aptos" =
          myLib.mkHomeManagerConfiguration { hostname = "aptos"; };

        "fcuny@tahoe" =
          myLib.mkHomeManagerConfiguration { hostname = "tahoe"; };
      };
    };
}