clan-core/checks/impure/flake-module.nix

76 lines
2.3 KiB
Nix
Raw Normal View History

2023-08-26 22:18:17 +00:00
{ self, ... }: {
2023-09-02 14:12:37 +00:00
perSystem = { pkgs, lib, self', ... }:
2023-08-26 22:18:17 +00:00
let
impureChecks = {
clan-pytest-impure = pkgs.writeShellScriptBin "clan-pytest-impure" ''
#!${pkgs.bash}/bin/bash
set -euo pipefail
2023-09-21 15:17:48 +00:00
export PATH="${lib.makeBinPath [
pkgs.gitMinimal
pkgs.nix
2023-09-21 15:17:48 +00:00
]}"
ROOT=$(git rev-parse --show-toplevel)
cd "$ROOT/pkgs/clan-cli"
nix develop "$ROOT#clan-cli" -c bash -c 'TMPDIR=/tmp python -m pytest -m impure -s ./tests'
'';
check-clan-template = pkgs.writeShellScriptBin "check-clan-template" ''
2023-08-26 22:18:17 +00:00
#!${pkgs.bash}/bin/bash
2023-09-21 15:17:48 +00:00
set -euox pipefail
2023-09-21 15:17:48 +00:00
export CLANTMP=$(${pkgs.coreutils}/bin/mktemp -d)
trap "${pkgs.coreutils}/bin/chmod -R +w '$CLANTMP'; ${pkgs.coreutils}/bin/rm -rf '$CLANTMP'" EXIT
2023-08-26 22:18:17 +00:00
export PATH="${lib.makeBinPath [
pkgs.coreutils
pkgs.curl
pkgs.gitMinimal
2023-09-02 14:12:37 +00:00
pkgs.gnugrep
pkgs.jq
pkgs.openssh
2023-08-26 22:18:17 +00:00
pkgs.nix
self'.packages.clan-cli
2023-08-26 22:18:17 +00:00
]}"
2023-09-21 15:17:48 +00:00
cd $CLANTMP
2023-08-26 22:18:17 +00:00
echo initialize new clan
nix flake init -t ${self}#new-clan
2023-09-02 14:12:37 +00:00
echo override clan input to the current version
nix flake lock --override-input clan-core ${self}
nix flake lock --override-input nixpkgs ${self.inputs.nixpkgs}
2023-08-26 22:18:17 +00:00
echo ensure flake outputs can be listed
nix flake show
2023-09-02 14:12:37 +00:00
echo create a machine
clan machines create machine1
2023-09-02 14:12:37 +00:00
echo check machine1 exists
clan machines list | grep -q machine1
2023-09-02 14:12:37 +00:00
echo check machine1 appears in nixosConfigurations
nix flake show --json | jq '.nixosConfigurations' | grep -q machine1
echo check machine1 jsonschema can be evaluated
nix eval .#nixosConfigurations.machine1.config.clanSchema
2023-08-26 22:18:17 +00:00
'';
};
in
{
packages =
impureChecks // {
2023-08-26 22:18:17 +00:00
# a script that executes all other checks
impure-checks = pkgs.writeShellScriptBin "impure-checks" ''
2023-08-26 22:18:17 +00:00
#!${pkgs.bash}/bin/bash
set -euo pipefail
${lib.concatMapStringsSep "\n" (name: ''
echo -e "\n\nrunning check ${name}\n"
${impureChecks.${name}}/bin/* "$@"
'') (lib.attrNames impureChecks)}
2023-08-26 22:18:17 +00:00
'';
};
};
}