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-2G9Bhflpw0BDcytKB4oOGIi3HR2fFd1rwZFcoIC09TQ=";
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 # mattn/go-sqlite3 needs cgo + a C compiler.
39 env.CGO_ENABLED = "1";
40 };
41 in {
42 # `nix fmt` formats the tree with alejandra. CI pins this same
43 # binary via `nix run nixpkgs#alejandra` for the format check.
44 formatter = pkgs.alejandra;
45
46 devShells.default = pkgs.mkShell {
47 packages = [
48 pkgs.go
49 ];
50 };
51
52 packages = {
53 default = tack;
54 tack = tack;
55 };
56
57 apps = {
58 default = {
59 type = "app";
60 program = "${tack}/bin/tack";
61 };
62 tack = {
63 type = "app";
64 program = "${tack}/bin/tack";
65 };
66 };
67 }
68 )
69 // {
70 # NixOS module. Operators add `imports = [ tack.nixosModules.default ];`
71 # and configure via `services.tangled.tack`. Mirrors the upstream
72 # Tangled module shape (services.tangled.spindle, .knot, …) so the
73 # config namespace is consistent.
74 nixosModules.default = {
75 lib,
76 pkgs,
77 ...
78 }: {
79 imports = [./nix/modules/tack.nix];
80
81 services.tangled.tack.package =
82 lib.mkDefault
83 self.packages.${pkgs.stdenv.hostPlatform.system}.tack;
84 };
85 nixosModules.tack = self.nixosModules.default;
86 };
87}