Stitch any CI into Tangled
1{
2 description = "tack";
3
4 inputs = {
5 nixpkgs.url = "https://channels.nixos.org/nixpkgs-unstable/nixexprs.tar.xz";
6 flake-utils.url = "github:numtide/flake-utils";
7 };
8
9 outputs = {
10 self,
11 nixpkgs,
12 flake-utils,
13 ...
14 }:
15 # Per-system outputs (packages, apps, devShells). nixosModules is
16 # system-independent and is merged in below.
17 flake-utils.lib.eachDefaultSystem (
18 system: let
19 pkgs = nixpkgs.legacyPackages.${system};
20
21 # The tack binary itself. We use buildGoModule because the module is
22 # a single `main` package at the repo root with internal subpackages.
23 # CGO is required for github.com/mattn/go-sqlite3.
24 tack = pkgs.buildGoModule {
25 pname = "tack";
26 version = "0.1.0";
27 src = ./.;
28
29 # vendorHash pins the Go module download FOD. Update this whenever
30 # go.mod / go.sum changes by replacing it with lib.fakeHash and
31 # rebuilding to surface the new hash.
32 vendorHash = "sha256-nTnfbKKswY1phPsRCTh/MCe4LdOeQfAJBqwRg3VK64M=";
33
34 # The repo ships a stale `tack` binary at the root that gets caught
35 # by `go test ./...`-style discovery; ignore it during the build.
36 subPackages = ["."];
37
38 # Fetch modules via the Go module proxy instead of synthesizing a
39 # vendor/ directory. We pull in deps (e.g. tangled.org/core ->
40 # go-redis/cache) whose test files require github.com/onsi/gomega;
41 # `go mod vendor` then refuses to build because gomega is in go.mod
42 # but not marked explicit in vendor/modules.txt. Proxy mode sidesteps
43 # the vendor consistency check entirely.
44 proxyVendor = true;
45
46 # mattn/go-sqlite3 needs cgo + a C compiler.
47 env.CGO_ENABLED = "1";
48 };
49 in {
50 # `nix fmt` formats the tree with alejandra. CI pins this same
51 # binary via `nix run nixpkgs#alejandra` for the format check.
52 formatter = pkgs.alejandra;
53
54 devShells.default = pkgs.mkShell {
55 packages = [
56 pkgs.go
57 ];
58 };
59
60 packages = {
61 default = tack;
62 tack = tack;
63 };
64
65 apps = {
66 default = {
67 type = "app";
68 program = "${tack}/bin/tack";
69 };
70 tack = {
71 type = "app";
72 program = "${tack}/bin/tack";
73 };
74 };
75 }
76 )
77 // {
78 # NixOS module. Operators add `imports = [ tack.nixosModules.default ];`
79 # and configure via `services.tangled.tack`. Mirrors the upstream
80 # Tangled module shape (services.tangled.spindle, .knot, …) so the
81 # config namespace is consistent.
82 nixosModules.default = {
83 lib,
84 pkgs,
85 ...
86 }: {
87 imports = [./nix/modules/tack.nix];
88
89 services.tangled.tack.package =
90 lib.mkDefault
91 self.packages.${pkgs.stdenv.hostPlatform.system}.tack;
92 };
93 nixosModules.tack = self.nixosModules.default;
94 };
95}