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 devShells.default = pkgs.mkShell {
43 packages = [
44 pkgs.go
45 ];
46 };
47
48 packages = {
49 default = tack;
50 tack = tack;
51 };
52
53 apps = {
54 default = {
55 type = "app";
56 program = "${tack}/bin/tack";
57 };
58 tack = {
59 type = "app";
60 program = "${tack}/bin/tack";
61 };
62 };
63 }
64 )
65 // {
66 # NixOS module. Operators add `imports = [ tack.nixosModules.default ];`
67 # and configure via `services.tangled.tack`. Mirrors the upstream
68 # Tangled module shape (services.tangled.spindle, .knot, …) so the
69 # config namespace is consistent.
70 nixosModules.default = {
71 lib,
72 pkgs,
73 ...
74 }: {
75 imports = [./nix/modules/tack.nix];
76
77 services.tangled.tack.package =
78 lib.mkDefault
79 self.packages.${pkgs.stdenv.hostPlatform.system}.tack;
80 };
81 nixosModules.tack = self.nixosModules.default;
82 };
83}