-
Notifications
You must be signed in to change notification settings - Fork 4
/
flake.nix
174 lines (149 loc) · 4.87 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
{
description = "A minesweeper game, written in Rust";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
naersk = {
url = "github:nmattia/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{ self
, fenix
, flake-utils
, gitignore
, naersk
, nixpkgs
, pre-commit-hooks
, ...
}:
flake-utils.lib.eachDefaultSystem (localSystem:
let
crossSystem = nixpkgs.lib.systems.examples.musl64 // { useLLVM = false; };
pkgs = import nixpkgs {
inherit localSystem crossSystem;
overlays = [
fenix.overlays.default
gitignore.overlay
naersk.overlay
(final: prev: {
rustToolchain =
let
fenixPackages = fenix.packages.${localSystem};
in
final.fenix.combine [
fenixPackages.latest.clippy-preview
fenixPackages.latest.rust-analysis
fenixPackages.latest.rust-analyzer-preview
fenixPackages.latest.rust-src
fenixPackages.latest.rust-std
fenixPackages.latest.rustfmt-preview
fenixPackages.minimal.cargo
fenixPackages.minimal.rustc
final.fenix.targets.${crossSystem.config}.latest.rust-std
];
rustStdenv = final.pkgsBuildHost.llvmPackages_16.stdenv;
rustLinker = final.pkgsBuildHost.llvmPackages_16.lld;
naerskBuild = (prev.pkgsBuildHost.naersk.override {
cargo = final.rustToolchain;
rustc = final.rustToolchain;
stdenv = final.rustStdenv;
}).buildPackage;
})
];
};
inherit (pkgs.lib) mkForce;
in
rec {
packages.minesweep = pkgs.naerskBuild {
pname = "minesweep";
src = pkgs.gitignoreSource ./.;
nativeBuildInputs = with pkgs; [ rustStdenv.cc rustLinker ];
CARGO_BUILD_TARGET = crossSystem.config;
RUSTFLAGS = "-C linker-flavor=ld.lld -C target-feature=+crt-static";
};
packages.default = packages.minesweep;
packages.minesweep-image = pkgs.pkgsBuildBuild.dockerTools.buildLayeredImage {
name = "minesweep";
config = {
Entrypoint = [ "${packages.minesweep}/bin/minesweep" ];
Command = [ "${packages.minesweep}/bin/minesweep" ];
};
};
apps.minesweep = flake-utils.lib.mkApp { drv = packages.minesweep; };
apps.default = apps.minesweep;
checks = {
pre-commit-check = pre-commit-hooks.lib.${localSystem}.run {
src = ./.;
hooks = {
statix.enable = true;
deadnix.enable = true;
nixpkgs-fmt.enable = true;
shellcheck.enable = true;
shfmt = {
enable = true;
entry = mkForce "${pkgs.pkgsBuildBuild.shfmt}/bin/shfmt -i 2 -sr -d -s -l";
files = "\\.sh$";
};
rustfmt = {
enable = true;
entry = mkForce "${pkgs.pkgsBuildBuild.rustToolchain}/bin/cargo fmt -- --check --color=always";
};
clippy = {
enable = true;
entry = mkForce "${pkgs.pkgsBuildBuild.rustToolchain}/bin/cargo clippy -- -D warnings";
};
cargo-check = {
enable = true;
entry = mkForce "${pkgs.pkgsBuildBuild.rustToolchain}/bin/cargo check";
};
prettier = {
enable = true;
entry = mkForce "${pkgs.pkgsBuildBuild.nodePackages.prettier}/bin/prettier --check";
types_or = [ "json" "yaml" "markdown" ];
};
taplo = {
enable = true;
entry = mkForce "${pkgs.pkgsBuildBuild.taplo-cli}/bin/taplo fmt";
types = [ "toml" ];
};
};
};
};
devShells.default = pkgs.mkShell {
inputsFrom = [ packages.minesweep ];
nativeBuildInputs = with pkgs.pkgsBuildBuild; [
cacert
cargo-audit
cargo-bloat
cargo-edit
cargo-udeps
deadnix
file
git
nixpkgs-fmt
statix
taplo-cli
];
inherit (self.checks.${localSystem}.pre-commit-check) shellHook;
};
});
}