blob: 5d21c4992536ee3b36587bb7561c80196687afc4 (
plain) (
tree)
|
|
{
description = "personal NixOS configurations";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
nixpkgsUnstable.url = "github:nixos/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager/release-25.05";
inputs.nixpkgs.follows = "nixpkgs";
};
darwin = {
url = "github:lnl7/nix-darwin/nix-darwin-25.05";
inputs.nixpkgs.follows = "nixpkgs";
};
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
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";
};
};
# Output config, or config for NixOS system
outputs =
{
self,
nixpkgs,
nixpkgsUnstable,
darwin,
treefmt-nix,
pre-commit-hooks,
emacs-overlay,
agenix,
...
}@inputs:
let
supportedSystems = [
"aarch64-darwin"
"x86_64-linux"
];
# Function to generate attributes for each system
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
# Function to get pkgs for a specific system
getPkgs =
system:
import nixpkgs {
inherit system;
config.allowUnfree = true;
overlays = overlays;
};
getPkgsUnstable =
system:
import nixpkgsUnstable {
inherit system;
};
# Define overlays here
overlays = [
emacs-overlay.overlay
(final: _prev: {
# Load all packages from the pkgs directory
customPackages = builtins.mapAttrs (
name: _:
final.callPackage (./pkgs + "/${name}") {
pkgsUnstable = getPkgsUnstable final.system;
}
) (builtins.readDir ./pkgs);
})
];
mkSystem = import ./nix/lib/mkSystem.nix {
inherit
self
nixpkgs
inputs
overlays
;
};
# Create a treefmt-nix evaluation for a system
mkTreefmtEval =
system:
let
pkgs = getPkgs system;
in
treefmt-nix.lib.evalModule pkgs {
projectRootFile = "flake.nix";
programs = {
nixfmt.enable = true;
deadnix.enable = true;
};
};
# Create pre-commit hooks for a system and source
mkPreCommitHooks =
system: src:
let
treefmtEval = mkTreefmtEval system;
in
inputs.pre-commit-hooks.lib.${system}.run {
inherit src;
hooks = {
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;
excludes = [ "\\.envrc$" ];
};
flake-checker.enable = true;
treefmt = {
enable = true;
entry = "${treefmtEval.config.build.wrapper}/bin/treefmt --ci";
};
trim-trailing-whitespace.enable = true;
};
};
in
{
# nix fmt
formatter = forAllSystems (
system:
let
treefmtEval = mkTreefmtEval system;
in
treefmtEval.config.build.wrapper
);
# nix flake check
checks = forAllSystems (system: {
pre-commit-check = mkPreCommitHooks system ./.;
});
# my VM running on the synology NAS
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;
};
# work laptop
darwinConfigurations.HQ-KWNY2VH41P = mkSystem "hq-kwny2vh41p" {
system = "aarch64-darwin";
user = "fcuny";
darwin = true;
};
# Dev shells for each system
devShells = forAllSystems (
system:
let
pkgs = getPkgs system;
pre-commit-check = mkPreCommitHooks system ./.;
scripts = import ./nix/scripts {
inherit pkgs system inputs;
};
in
{
default = pkgs.mkShellNoCC {
inherit (pre-commit-check) shellHook; # This is the key line
packages =
with pkgs;
[
nixos-rebuild
git
inputs.agenix.packages."${system}".default
]
++ scripts.all;
};
}
);
};
}
|