flake.nix
1# ci: a Nix-native, Tangled-compatible CI/CD engine and its hosts (bridge,
2# runner, appview). See DESIGN.md.
3#
4# Other repos pin the engine through their devenv (see README.md), so local
5# runs and the runner use the same engine for a given commit.
6{
7 description = "Nix-native Tangled-compatible CI/CD";
8
9 inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
10
11 outputs =
12 { self, nixpkgs }:
13 let
14 inherit (nixpkgs) lib;
15 systems = [
16 "x86_64-linux"
17 "aarch64-linux"
18 ];
19 forAllSystems = f: lib.genAttrs systems (system: f nixpkgs.legacyPackages.${system});
20 version = self.shortRev or self.dirtyShortRev or "dev";
21 in
22 {
23 packages = forAllSystems (pkgs: rec {
24 ci = pkgs.buildGoModule {
25 pname = "ci";
26 inherit version;
27 src = lib.fileset.toSource {
28 root = ./.;
29 fileset = lib.fileset.unions [
30 ./go.mod
31 (lib.fileset.maybeMissing ./go.sum)
32 ./cmd
33 ./internal
34 ./lexicons
35 ];
36 };
37 vendorHash = "sha256-EQJSRDpp6xxGbVWVUxaOMWjsvuIbiixnE6jRGmiatZI=";
38 subPackages = [ "cmd/ci" ];
39 env.CGO_ENABLED = "0";
40 ldflags = [ "-X main.version=${version}" ];
41 postInstall = ''
42 ln -s ci $out/bin/ci-result
43 '';
44 meta = {
45 description = "Nix-native Tangled-compatible CI/CD engine";
46 mainProgram = "ci";
47 license = lib.licenses.mit;
48 };
49 };
50 default = ci;
51 });
52
53 # services.ci.{bridge,runner,appview}; see nix/module.nix.
54 nixosModules.default = import ./nix/module.nix self;
55
56 overlays.default = final: _prev: {
57 ci = self.packages.${final.stdenv.hostPlatform.system}.ci;
58 };
59
60 # The whole test suite (the package's own check only covers cmd/ci).
61 # Engine, checkout and runner tests drive real git and bash.
62 checks = forAllSystems (pkgs: {
63 tests = self.packages.${pkgs.stdenv.hostPlatform.system}.ci.overrideAttrs (old: {
64 pname = "ci-tests";
65 nativeCheckInputs = [
66 pkgs.git
67 pkgs.jq
68 pkgs.bash
69 ];
70 checkPhase = ''
71 runHook preCheck
72 export HOME=$TMPDIR
73 go test ./...
74 runHook postCheck
75 '';
76 });
77 }
78 // lib.optionalAttrs pkgs.stdenv.hostPlatform.isx86_64 {
79 # a NixOS VM: soft-serve + bridge + runner (systemd) + appview
80 e2e = import ./nix/tests/e2e.nix { inherit self pkgs; };
81 });
82 };
83}