add flake module

This commit is contained in:
Emile Clark-Boman 2026-01-27 17:50:53 +10:00
parent 3fe748f174
commit bc2a62e62b
4 changed files with 84 additions and 0 deletions

10
flake/default.nix Normal file
View file

@ -0,0 +1,10 @@
{mix, ...} @ inputs:
mix.newMixture inputs (mixture: {
includes.public = [
./devshells.nix
./nix-unit.nix
];
submods.private = [
./util.nix
];
})

20
flake/devshells.nix Normal file
View file

@ -0,0 +1,20 @@
{this, ...}: let
inherit
(this.util)
forAllSystems
;
in {
devShells = forAllSystems (
system: pkgs: {
default = pkgs.mkShell {
packages = with pkgs; [
python312
nix-unit
nixfmt
];
shell = "${pkgs.bash}/bin/bash";
};
}
);
}

34
flake/nix-unit.nix Normal file
View file

@ -0,0 +1,34 @@
{
this,
flake,
deps,
...
}: let
inherit
(deps)
nixpkgs
nix-unit
;
inherit
(this.util)
forAllSystems
;
in {
checks = forAllSystems (system: {
default =
nixpkgs.legacyPackages.${system}.runCommand "tests"
{
nativeBuildInputs = [nix-unit.packages.${system}.default];
}
''
export HOME="$(realpath .)"
# The nix derivation must be able to find all used inputs in the nix-store because it cannot download it during buildTime.
nix-unit --eval-store "$HOME" \
--extra-experimental-features flakes \
--override-input nixpkgs ${nixpkgs} \
--flake ${flake}#tests
touch $out
'';
});
}

20
flake/util.nix Normal file
View file

@ -0,0 +1,20 @@
{
flake,
systems,
nixpkgs,
...
}: let
inherit
(builtins)
attrValues
;
in {
forAllSystems = f:
nixpkgs.lib.genAttrs systems (system:
f system (import nixpkgs {
inherit system;
allowUnfree = false;
allowBroken = false;
overlays = attrValues flake.overlays;
}));
}