-
-
Notifications
You must be signed in to change notification settings - Fork 279
/
flake.nix
93 lines (87 loc) · 2.74 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{
description = "templ";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-24.05";
gomod2nix = {
url = "github:nix-community/gomod2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
xc = {
url = "github:joerdav/xc";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, gomod2nix, gitignore, xc }:
let
allSystems = [
"x86_64-linux" # 64-bit Intel/AMD Linux
"aarch64-linux" # 64-bit ARM Linux
"x86_64-darwin" # 64-bit Intel macOS
"aarch64-darwin" # 64-bit ARM macOS
];
forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
inherit system;
pkgs = import nixpkgs { inherit system; };
});
in
{
packages = forAllSystems ({ system, pkgs, ... }:
let
buildGoApplication = gomod2nix.legacyPackages.${system}.buildGoApplication;
in
rec {
default = templ;
templ = buildGoApplication {
name = "templ";
src = gitignore.lib.gitignoreSource ./.;
# Update to latest Go version when https://nixpk.gs/pr-tracker.html?pr=324123 is backported to release-24.05.
go = pkgs.go;
# Must be added due to bug https://github.com/nix-community/gomod2nix/issues/120
pwd = ./.;
subPackages = [ "cmd/templ" ];
CGO_ENABLED = 0;
flags = [
"-trimpath"
];
ldflags = [
"-s"
"-w"
"-extldflags -static"
];
};
});
# `nix develop` provides a shell containing development tools.
devShell = forAllSystems ({ system, pkgs }:
pkgs.mkShell {
buildInputs = with pkgs; [
golangci-lint
cosign # Used to sign container images.
esbuild # Used to package JS examples.
go_1_22
gomod2nix.legacyPackages.${system}.gomod2nix
gopls
goreleaser
gotestsum
ko # Used to build Docker images.
nodejs # Used to build templ-docs.
xc.packages.${system}.xc
];
});
# This flake outputs an overlay that can be used to add templ and
# templ-docs to nixpkgs as per https://templ.guide/quick-start/installation/#nix
#
# Example usage:
#
# nixpkgs.overlays = [
# inputs.templ.overlays.default
# ];
overlays.default = final: prev: {
templ = self.packages.${final.stdenv.system}.templ;
templ-docs = self.packages.${final.stdenv.system}.templ-docs;
};
};
}