-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathflake.nix
More file actions
120 lines (109 loc) · 3.29 KB
/
flake.nix
File metadata and controls
120 lines (109 loc) · 3.29 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# New to Nix? Start here:
# Language basics: https://nix.dev/tutorials/nix-language
# Flakes intro: https://zero-to-nix.com/concepts/flakes
{
description = "Crossplane Runtime - Go library for building Crossplane providers and controllers";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
# TODO(negz): Unpin once https://github.com/nix-community/gomod2nix/pull/231 is released.
gomod2nix = {
url = "github:nix-community/gomod2nix/49662a44272806ff785df2990a420edaaca15db4";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
nixpkgs-unstable,
gomod2nix,
}:
let
# Systems where Nix runs (dev machines, CI).
supportedSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
# Helpers for per-system outputs.
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: forSystem system f);
forSystem =
system: f:
f {
inherit system;
pkgs = import nixpkgs {
inherit system;
overlays = [
gomod2nix.overlays.default
(_final: _prev: {
go = nixpkgs-unstable.legacyPackages.${system}.go_1_25;
inherit (nixpkgs-unstable.legacyPackages.${system}) go_1_25;
})
];
};
};
in
{
# CI checks (nix flake check).
checks = forAllSystems (
{ pkgs, ... }:
let
checks = import ./nix/checks.nix { inherit pkgs self; };
in
{
test = checks.test { };
generate = checks.generate { };
go-lint = checks.goLint { };
nix-lint = checks.nixLint { };
}
);
# Development commands (nix run .#<app>).
apps = forAllSystems (
{ pkgs, ... }:
let
apps = import ./nix/apps.nix { inherit pkgs; };
in
{
test = apps.test { };
lint = apps.lint { fix = true; };
generate = apps.generate { };
tidy = apps.tidy { };
}
);
# Development shell (nix develop).
devShells = forAllSystems (
{ pkgs, ... }:
{
default = pkgs.mkShell {
buildInputs = [
pkgs.coreutils
pkgs.gnused
pkgs.ncurses
pkgs.go
pkgs.golangci-lint
pkgs.gomod2nix
# Code generation
pkgs.buf
pkgs.protoc-gen-go
pkgs.protoc-gen-go-grpc
pkgs.kubernetes-controller-tools
# Nix
pkgs.nixfmt-rfc-style
];
shellHook = ''
export PS1='\[\033[38;2;243;128;123m\][cros\[\033[38;2;255;205;60m\]spla\[\033[38;2;53;208;186m\]ne-rt]\[\033[0m\] \w \$ '
echo "Crossplane Runtime development shell ($(go version | cut -d' ' -f3))"
echo ""
echo " nix run .#test nix run .#generate"
echo " nix run .#lint nix run .#tidy"
echo ""
echo " nix flake check"
echo ""
'';
};
}
);
};
}