forked from mpiorowski/late-sh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
145 lines (127 loc) · 4.75 KB
/
flake.nix
File metadata and controls
145 lines (127 loc) · 4.75 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
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
{
description = "late.sh — a social SSH terminal";
inputs = {
# For listing and iterating nix systems
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
# For installing non-standard rustc versions
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = {
self,
nixpkgs,
flake-utils,
rust-overlay,
}:
{
overlays.default = final: prev: {
late-sh = self.packages.${final.stdenv.hostPlatform.system}.late-sh;
};
}
// (flake-utils.lib.eachSystem nixpkgs.lib.systems.flakeExposed (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [
rust-overlay.overlays.default
];
};
# When we're running in the shell, we want rustc with a bunch of extra
# bits so that rust-analyzer, clippy, rustfmt, etc. all work out of the
# box.
rustShellToolchain = pkgs.rust-bin.stable.latest.default.override {
# NOTE: explicitly add rust-src to the rustc compiler only in devShell.
# this in turn causes a dependency on the rust compiler src, which
# bloats the closure size by several GiB. but doing this here and not
# by default avoids the default flake install from including that
# dependency, so it's worth it.
extensions = [
"rust-src"
"rust-analyzer"
"llvm-tools-preview"
];
};
# But, whenever we are running CI builds or checks, we want to use a
# smaller closure. This reduces the CI impact on fresh clones/VMs, etc.
rustMinimalPlatform = let
platform = pkgs.rust-bin.stable.latest.minimal;
in
pkgs.makeRustPlatform {
rustc = platform;
cargo = platform;
};
in {
formatter = pkgs.alejandra;
packages = {
late-sh = pkgs.callPackage ./default.nix {
rustPlatform = rustMinimalPlatform;
gitRev = self.rev or self.dirtyRev or null;
};
default = self.packages.${system}.late-sh;
};
checks.late-sh = self.packages.${system}.late-sh.overrideAttrs ({...}: {
# The default Rust infrastructure runs all builds in the release
# profile, which is significantly slower. Run this under the `test`
# profile instead
cargoBuildType = "test";
cargoCheckType = "test";
buildPhase = "true";
installPhase = "touch $out";
});
devShells.default = let
packages = with pkgs; [
rustShellToolchain
llvmPackages.llvm # for e.g. llvm-symbolizer
# Matches .mise.toml / CONTRIBUTING tooling
mold
cargo-nextest
typos
# Commonly useful cargo helpers
cargo-llvm-cov
cargo-watch
cargo-autoinherit
cargo-msrv
# late-web frontend tooling
nodejs
tailwindcss_4
# Integration / infra tooling (docker-compose stack, migrations, etc.)
postgresql
docker-compose
# Commit signing
gnupg
];
# on macOS and Linux, use faster parallel linkers that are much more
# efficient than the defaults. these noticeably improve link time even
# for medium sized rust projects.
rustLinkerFlags =
if pkgs.stdenv.isLinux
then ["-fuse-ld=mold" "-Wl,--compress-debug-sections=zstd"]
else if pkgs.stdenv.isDarwin
then
# on darwin, /usr/bin/ld actually looks at the environment variable
# $DEVELOPER_DIR, which is set by the nix stdenv, and if set,
# automatically uses it to route the `ld` invocation to the binary
# within. in the devShell though, that isn't what we want; it's
# functional, but Xcode's linker as of ~v15 (not yet open source)
# is ultra-fast and very shiny; it is enabled via -ld_new, and on by
# default as of v16+
["--ld-path=$(unset DEVELOPER_DIR; /usr/bin/xcrun --find ld)" "-ld_new"]
else [];
rustLinkFlagsString =
pkgs.lib.concatStringsSep " "
(pkgs.lib.concatMap (x: ["-C" "link-arg=${x}"]) rustLinkerFlags);
# The `RUSTFLAGS` environment variable is set in `shellHook` instead of
# `env` to allow the `xcrun` command above to be interpreted by the
# shell.
shellHook = ''
export RUSTFLAGS="${rustLinkFlagsString}"
'';
late-sh = self.packages.${system}.late-sh;
in
pkgs.mkShell {
name = "late-sh";
packages = packages ++ late-sh.nativeBuildInputs ++ late-sh.buildInputs;
inherit shellHook;
};
}));
}