Skip to content

Commit

Permalink
add flake structure checks
Browse files Browse the repository at this point in the history
  • Loading branch information
cottand committed Aug 10, 2024
1 parent e267955 commit 462820a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
32 changes: 32 additions & 0 deletions checks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
All the attributes of this set should be derivations that always build successfully.
These are used to validate that this repo and this flake
*/
{ self, system, stdenvNoCC, lib, ... }:
let
inherit (lib.asserts) assertMsg;
noDerivationTest = { name, errorMsg, checkPhase ? "", assertThat ? true, }:
stdenvNoCC.mkDerivation {
inherit checkPhase name;
dontBuild = true;
doCheck = true;
src = ./.;
installPhase = ''
mkdir "$out"
'';
_ASSERT = assertMsg assertThat errorMsg;
};
in
{
servicesHaveImageAttribute = noDerivationTest {
name = "services-have-image-attribute";
assertThat = with builtins;
let
services = self.legacyPackages.${system}.services;
hasImageAttr = name: svc: assertMsg (svc ? "image") "expected to find .image attribute in ${svc}";
in
all (x: x) (attrValues (mapAttrs hasImageAttr services));
errorMsg = "expected all services to have a .image attribute";
};

}
15 changes: 9 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,22 @@
vault-bin = (import nixpkgs-master { system = prev.system; config.allowUnfree = true; }).vault-bin;
};
withScripts = final: prev: {
scripts = self.legacyPackages.${prev.system}.scripts;
scripts = self.legacyPackages.${prev.system}.scripts;
};
overlays = [ (import ./overlay.nix) withScripts newVault attic.overlays.default ];
in
{
colmena = (import ./hive.nix) (inputs // { inherit overlays; });
} // (utils.lib.eachDefaultSystem (system:
(utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system overlays;
config.allowUnfree = true;
};
pkgsWithSelf = pkgs // {inherit self; };
in
rec {

legacyPackages.services = (import ./services) pkgs;
legacyPackages.scripts = (import ./scripts) (pkgs // {inherit self; });
legacyPackages.scripts = (import ./scripts) pkgsWithSelf;

packages = legacyPackages.scripts;

Expand Down Expand Up @@ -80,10 +79,14 @@
VAULT_ADDR = "https://vault.mesh.dcotta.eu:8200";
};

checks = (import ./checks.nix) pkgsWithSelf;

formatter = pkgs.writeShellScriptBin "fmt" ''
${pkgs.nomad}/bin/nomad fmt
${pkgs.terraform}/bin/terraform fmt
'';
}
));
)) // {
colmena = (import ./hive.nix) (inputs // { inherit overlays; }); }
;
}

0 comments on commit 462820a

Please sign in to comment.