mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-04-25 10:18:37 +02:00
refactor: Use haumea for filesystem-based module system for flake outputs
refactor: Use hyphen(`-`) for variable names & folder names(except Python), replace all unserscore(`_`) with hyphen(`-`).
This commit is contained in:
135
outputs/default.nix
Normal file
135
outputs/default.nix
Normal file
@@ -0,0 +1,135 @@
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
pre-commit-hooks,
|
||||
...
|
||||
} @ inputs: let
|
||||
inherit (inputs.nixpkgs) lib;
|
||||
mylib = import ../lib {inherit lib;};
|
||||
myvars = import ../vars {inherit lib;};
|
||||
|
||||
# Add my custom lib, vars, nixpkgs instance, and all the inputs to sepcialArgs,
|
||||
# so that I can use them in all my nixos/home-manager/darwin modules.
|
||||
genSpecialArgs = system:
|
||||
inputs
|
||||
// {
|
||||
inherit mylib myvars;
|
||||
|
||||
# use unstable branch for some packages to get the latest updates
|
||||
pkgs-unstable = import inputs.nixpkgs-unstable {
|
||||
inherit system; # refer the `system` parameter form outer scope recursively
|
||||
# To use chrome, we need to allow the installation of non-free software
|
||||
config.allowUnfree = true;
|
||||
};
|
||||
pkgs-stable = import inputs.nixpkgs-stable {
|
||||
inherit system;
|
||||
# To use chrome, we need to allow the installation of non-free software
|
||||
config.allowUnfree = true;
|
||||
};
|
||||
};
|
||||
|
||||
# This is the args for all the haumea modules in this folder.
|
||||
args = {inherit inputs lib mylib myvars genSpecialArgs;};
|
||||
|
||||
# modules for each supported system
|
||||
nixosSystems = {
|
||||
x86_64-linux = import ./x86_64-linux (args // {system = "x86_64-linux";});
|
||||
aarch64-linux = import ./aarch64-linux (args // {system = "aarch64-linux";});
|
||||
riscv64-linux = import ./riscv64-linux (args // {system = "riscv64-linux";});
|
||||
};
|
||||
darwinSystems = {
|
||||
aarch64-darwin = import ./aarch64-darwin (args // {system = "aarch64-darwin";});
|
||||
x86_64-darwin = import ./x86_64-darwin (args // {system = "x86_64-darwin";});
|
||||
};
|
||||
allSystems = nixosSystems // darwinSystems;
|
||||
allSystemNames = builtins.attrNames allSystems;
|
||||
nixosSystemValues = builtins.attrValues nixosSystems;
|
||||
darwinSystemValues = builtins.attrValues darwinSystems;
|
||||
|
||||
# Helper function to generate a set of attributes for each system
|
||||
forAllSystems = func: (nixpkgs.lib.genAttrs allSystemNames func);
|
||||
in {
|
||||
# add attribute sets into outputs, for debugging
|
||||
debugAttrs = {inherit nixosSystems darwinSystems allSystems allSystemNames;};
|
||||
|
||||
# NixOS Hosts
|
||||
nixosConfigurations =
|
||||
lib.attrsets.mergeAttrsList (map (it: it.nixosConfigurations or {}) nixosSystemValues);
|
||||
|
||||
# colmena - remote deployment via SSH
|
||||
colmena =
|
||||
{
|
||||
meta =
|
||||
(
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
in {
|
||||
# colmena's default nixpkgs & specialArgs
|
||||
nixpkgs = import nixpkgs {inherit system;};
|
||||
specialArgs = genSpecialArgs system;
|
||||
}
|
||||
)
|
||||
// {
|
||||
# per-node nixpkgs & specialArgs
|
||||
nodeNixpkgs = lib.attrsets.mergeAttrsList (map (it: it.colmena-meta.nodeNixpkgs or {}) nixosSystemValues);
|
||||
nodeSpecialArgs = lib.attrsets.mergeAttrsList (map (it: it.colmena-meta.nodeSpecialArgs or {}) nixosSystemValues);
|
||||
};
|
||||
}
|
||||
// lib.attrsets.mergeAttrsList (map (it: it.colmena or {}) nixosSystemValues);
|
||||
|
||||
# macOS Hosts
|
||||
darwinConfigurations =
|
||||
lib.attrsets.mergeAttrsList (map (it: it.darwinConfigurations or {}) darwinSystemValues);
|
||||
|
||||
# Packages
|
||||
packages = forAllSystems (
|
||||
system: allSystems.${system}.packages or {}
|
||||
);
|
||||
|
||||
# Unit Tests, Intergraded Tests, and Pre-commit checks
|
||||
checks = forAllSystems (
|
||||
system: {
|
||||
# Unit Tests for the system
|
||||
# unit-tests = allSystems.${system}.unit-tests;
|
||||
|
||||
pre-commit-check = pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
alejandra.enable = true; # formatter
|
||||
# deadnix.enable = true; # detect unused variable bindings in `*.nix`
|
||||
# statix.enable = true; # lints and suggestions for Nix code(auto suggestions)
|
||||
# prettier = {
|
||||
# enable = true;
|
||||
# excludes = [".js" ".md" ".ts"];
|
||||
# };
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
# Development Shells
|
||||
devShells = forAllSystems (
|
||||
system: let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in {
|
||||
default = pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
# fix https://discourse.nixos.org/t/non-interactive-bash-errors-from-flake-nix-mkshell/33310
|
||||
bashInteractive
|
||||
# fix `cc` replaced by clang, which causes nvim-treesitter compilation error
|
||||
gcc
|
||||
];
|
||||
name = "dots";
|
||||
shellHook = ''
|
||||
${self.checks.${system}.pre-commit-check.shellHook}
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
# Format the nix code in this flake
|
||||
formatter = forAllSystems (
|
||||
# alejandra is a nix formatter with a beautiful output
|
||||
system: nixpkgs.legacyPackages.${system}.alejandra
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user