nixos/flake.nix

142 lines
3.8 KiB
Nix

{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
nixpkgsUnstable.url = "github:NixOS/nixpkgs/nixos-unstable";
nixos-hardware.url = "github:NixOS/nixos-hardware/master";
home-manager = {
url = "github:nix-community/home-manager/release-25.05";
inputs.nixpkgs.follows = "nixpkgs";
};
agenix.url = "github:ryantm/agenix";
simple-nixos-mailserver.url = "gitlab:simple-nixos-mailserver/nixos-mailserver/nixos-25.05";
git-hooks = {
url = "github:cachix/git-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-programs-sqlite = {
url = "github:wamserma/flake-programs-sqlite";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
inputs@{
nixpkgs,
nixpkgsUnstable,
home-manager,
nixos-hardware,
agenix,
simple-nixos-mailserver,
git-hooks,
...
}:
let
system = "x86_64-linux";
overlayUnstable = _final: _prev: {
unstable = import nixpkgsUnstable {
inherit system;
config.allowUnfree = true;
config.android_sdk.accept_license = true;
};
};
# Common modules shared across all hosts
commonModules = [
agenix.nixosModules.default
{
environment.systemPackages = [ agenix.packages.${system}.default ];
}
{
nixpkgs.overlays = [ overlayUnstable ];
}
inputs.flake-programs-sqlite.nixosModules.programs-sqlite
];
# Common home-manager modules
homeManagerModules = [
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
}
];
# Helper function to create a host configuration
mkHost =
{
hostPath,
extraModules ? [ ],
includeHomeManager ? true,
specialArgs ? { },
}:
nixpkgs.lib.nixosSystem {
inherit system specialArgs;
modules =
commonModules
++ (if includeHomeManager then homeManagerModules else [ ])
++ extraModules
++ [ hostPath ];
};
in
rec {
nixosConfigurations = {
nixbox = mkHost {
hostPath = ./hosts/nixbox;
};
flynode = mkHost {
hostPath = ./hosts/flynode;
extraModules = [ nixos-hardware.nixosModules.lenovo-thinkpad-z13-gen1 ];
};
thewordnerd = mkHost {
hostPath = ./hosts/hub;
extraModules = [ simple-nixos-mailserver.nixosModule ];
specialArgs = { inherit inputs; };
};
garden = mkHost {
hostPath = ./hosts/garden;
includeHomeManager = false;
specialArgs = { inherit inputs; };
};
router = mkHost {
hostPath = ./hosts/router;
};
};
checks.${system} = {
pre-commit-check = git-hooks.lib.${system}.run {
src = ./.;
hooks = {
# Check formatting of flake.nix
nixfmt-rfc-style = {
enable = true;
files = "^flake\\.nix$";
};
# Check for dead code in flake.nix
deadnix = {
enable = true;
files = "^flake\\.nix$";
};
# Flake-specific checks
flake-checker.enable = true;
};
};
};
devShells.${system}.default =
let
pkgs = nixpkgs.legacyPackages.${system};
in
pkgs.mkShell {
inherit (checks.${system}.pre-commit-check) shellHook;
buildInputs = checks.${system}.pre-commit-check.enabledPackages;
nativeBuildInputs = with pkgs; [
nil
nixfmt-rfc-style
];
};
};
}