nix/flake.nix
2025-04-08 23:41:12 -05:00

154 lines
4.3 KiB
Nix

{
description = "Ray's Nix Config";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
ghostty.url = "github:ghostty-org/ghostty";
nix-index-database.url = "github:nix-community/nix-index-database";
nix-index-database.inputs.nixpkgs.follows = "nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
git-hooks.url = "github:cachix/git-hooks.nix";
git-hooks.inputs.nixpkgs.follows = "nixpkgs";
sops-nix.url = "github:Mic92/sops-nix";
sops-nix.inputs.nixpkgs.follows = "nixpkgs";
# linux-only
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
disko.url = "github:nix-community/disko";
disko.inputs.nixpkgs.follows = "nixpkgs";
zen-browser.url = "github:0xc000022070/zen-browser-flake";
zen-browser.inputs.nixpkgs.follows = "nixpkgs";
# darwin-only
nix-darwin.url = "github:nix-darwin/nix-darwin/master";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
mac-app-util.url = "github:hraban/mac-app-util";
nixpkgs-firefox-darwin.url = "github:bandithedoge/nixpkgs-firefox-darwin";
nix-homebrew.url = "github:zhaofengli/nix-homebrew";
homebrew-core.url = "github:homebrew/homebrew-core";
homebrew-core.flake = false;
homebrew-cask.url = "github:homebrew/homebrew-cask";
homebrew-cask.flake = false;
homebrew-createzap.url = "github:nrlquaker/homebrew-createzap";
homebrew-createzap.flake = false;
};
outputs =
{
self,
nixpkgs,
home-manager,
treefmt-nix,
...
}@inputs:
let
inherit (self) outputs;
user = "rayandrew";
lib = nixpkgs.lib;
commonArgs = {
inherit
self
inputs
nixpkgs
lib
;
specialArgs = {
inherit self inputs;
};
};
# call with forAllSystems (commonArgs: function body)
forAllSystems =
fn:
lib.genAttrs
[
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
]
(
system:
fn (
commonArgs
// {
inherit system;
pkgs = import inputs.nixpkgs {
inherit system;
config.allowUnfree = true;
};
}
)
);
treefmtEval = forAllSystems (
{ pkgs, ... }:
treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
programs.nixfmt.enable = true;
programs.stylua.enable = true;
programs.shfmt.enable = true;
settings.global.excludes = [ "flake.lock" ];
}
);
in
(import ./hosts commonArgs)
// {
checks = forAllSystems (
{
pkgs,
system,
...
}:
{
formatting = treefmtEval.${system}.config.build.check self;
pre-commit-check = inputs.git-hooks.lib.${system}.run {
src = ./.;
excludes = [ "flake.lock" ];
hooks = {
treefmt = {
enable = true;
package = lib.mkForce treefmtEval.${system}.config.build.wrapper;
args = [
# "--config-file ${treefmtEval.${system}.config.build.configFile}"
];
};
};
};
}
);
devShells = forAllSystems (
{
pkgs,
system,
...
}:
{
default = pkgs.mkShell {
inherit (self.checks.${system}.pre-commit-check) shellHook;
name = "dotfiles";
buildInputs = self.checks.${system}.pre-commit-check.enabledPackages;
nativeBuildInputs = [
treefmtEval.${system}.config.build.wrapper
];
packages = with pkgs; [
sops
age
ssh-to-age
# nixfmt-rfc-style
];
DIRENV_LOG_FORMAT = "";
};
}
);
packages = forAllSystems (commonArgs': (import ./packages commonArgs'));
formatter = forAllSystems ({ system, ... }: treefmtEval.${system}.config.build.wrapper);
};
}