This flake exposes and API to detect if Nix is run in a continuous integration(CI) environment or not. This project has been inspired by OndraM/ci-detector library for PHP.
Warning: Since detecting if we are in a CI or not rely on environment variables, we must add the flag
--impure
to the nix command.
In command line:
$ nix eval github:loophp/ci-detector#lib.inCI --impure
false
Now faking a Github actions environment by setting the GITHUB_ACTIONS
variable:
$ GITHUB_ACTIONS="FOOBAR" nix eval github:loophp/ci-detector#lib.inCI --impure
true
This package contains a flake.nix
which exposes an API.
Exposed API:
lib.ci
: When running in a CI, returns aset
containing the current CI environment information, throws an error otherwise.lib.inCI
: When running in a CI, returnstrue
,false
otherwise.lib.notInCI
: When running in a CI, returnsfalse
,true
otherwise.lib.find
: Unary function where the first argument is a default value. When in a CI, the CI information is returned, otherwise the default value is returned.
To use it in your own package, take example on the following minimum working example:
{
description = "Simple example flake";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
ci-detector.url = "github:loophp/ci-detector";
};
outputs = { self, nixpkgs, flake-utils, ci-detector, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
ci = ci-detector.lib.find { name = "local"; };
in
{
devShells.default = pkgs.mkShellNoCC {
name = "${ci.name}-devshell";
};
});
}