flake-base/flake.nix

90 lines
2.3 KiB
Nix
Raw Normal View History

{
description = "A simple base flake to be used as a starting point to avoid setting up everything for every flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
snowfall-lib = {
url = "github:snowfallorg/lib";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs = {
nixpkgs.follows = "nixpkgs";
};
};
};
outputs =
{
self,
nixpkgs,
snowfall-lib,
treefmt-nix,
}:
let
eachSystemOp =
op: systems: f:
builtins.foldl' (op f) { } systems;
2025-07-05 14:34:16 +02:00
in
{
lib.eachSystem = eachSystemOp (
f: attrs: system:
let
result = f system;
in
builtins.foldl' (
attrs: key:
attrs
// {
${key} = (attrs.${key} or { }) // {
${system} = result.${key};
};
}
2025-07-05 11:17:16 +02:00
) attrs (builtins.attrNames result)
);
lib.mkFlake =
options@{
flakeBaseSystems ? [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
],
devShellPackages ? (pkgs: [ ]),
treeFmtFile ? ./treefmt.nix,
...
}:
let
snowfallOptions = builtins.removeAttrs options [
"flakeBaseSystems"
"devShellPackages"
"treeFmtFile"
];
2025-07-05 15:09:30 +02:00
flake = snowfall-lib.mkFlake snowfallOptions;
in
2025-07-05 15:09:30 +02:00
flake
2025-07-05 14:34:16 +02:00
// (self.lib.eachSystem flakeBaseSystems (
system:
let
pkgs = import nixpkgs { inherit system; };
treeFmtEval = treefmt-nix.lib.evalModule pkgs treeFmtFile;
in
{
2025-07-05 15:09:30 +02:00
formatter = flake.formatter.${system} or treeFmtEval.config.build.wrapper;
checks = flake.checks.${system} // {
fmt = treeFmtEval.config.build.check self;
2025-07-05 15:09:30 +02:00
};
devShells = flake.devShells.${system} // {
default =
flake.devShells.${system}.default or (pkgs.mkShell {
packages = [
pkgs.nixfmt-rfc-style
pkgs.nixd
] ++ (devShellPackages pkgs);
});
};
}
));
};
}