diff --git a/flake/default.nix b/flake/default.nix new file mode 100644 index 0000000..c68af00 --- /dev/null +++ b/flake/default.nix @@ -0,0 +1,10 @@ +{mix, ...} @ inputs: +mix.newMixture inputs (mixture: { + includes.public = [ + ./devshells.nix + ./nix-unit.nix + ]; + submods.private = [ + ./util.nix + ]; +}) diff --git a/flake/devshells.nix b/flake/devshells.nix new file mode 100644 index 0000000..27a0b89 --- /dev/null +++ b/flake/devshells.nix @@ -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"; + }; + } + ); +} diff --git a/flake/nix-unit.nix b/flake/nix-unit.nix new file mode 100644 index 0000000..a07952d --- /dev/null +++ b/flake/nix-unit.nix @@ -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 + ''; + }); +} diff --git a/flake/util.nix b/flake/util.nix new file mode 100644 index 0000000..e5e80ce --- /dev/null +++ b/flake/util.nix @@ -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; + })); +}