-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
150 lines (140 loc) · 6 KB
/
Copy pathflake.nix
File metadata and controls
150 lines (140 loc) · 6 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
146
147
148
149
150
{
description = "binvim — Vim-grammar TUI editor with batteries included.";
inputs = {
# nixpkgs-unstable carries a recent enough rustc for edition-2024 +
# `rust-version = 1.85` in Cargo.toml. If your channel pins older
# nixpkgs, override this input with `--override-input nixpkgs <ref>`
# or pin a fresher branch in your own flake.
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
let
# Source-available, redistribution prohibited — see LICENSE. The
# nixpkgs predefined `unfree` tag is the closest fit but loses the
# specifics; declaring it inline keeps the actual terms visible to
# `nix-env -qa --json` consumers.
binvimLicense = {
fullName = "binvim Source-Available License (BSAL) v1.1";
url = "https://github.com/bgunnarsson/binvim/blob/main/LICENSE";
free = false;
redistributable = false;
};
# Read the version out of Cargo.toml so the flake never drifts from
# the crates.io / Homebrew / GitHub Release source of truth.
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
in
flake-utils.lib.eachDefaultSystem
(system:
let
# `allowUnfreePredicate` keeps the unfree gate scoped to this
# one package. Without it, `nix run github:bgunnarsson/binvim`
# errors out with "refusing to evaluate" because we tagged the
# license `free = false` above — users would have to set
# `NIXPKGS_ALLOW_UNFREE=1` + pass `--impure` to every command.
# Scoping it inside the flake means downstream consumers don't
# have to reconfigure nixpkgs to install one editor.
pkgs = import nixpkgs {
inherit system;
config.allowUnfreePredicate = pkg:
builtins.elem (pkgs.lib.getName pkg) [ "binvim" ];
};
binvim = pkgs.rustPlatform.buildRustPackage {
pname = "binvim";
version = cargoToml.package.version;
src = ./.;
# `lockFile` re-uses the committed Cargo.lock so the
# nix-built binary matches what `cargo install --locked
# binvim` produces on a host system.
cargoLock = {
lockFile = ./Cargo.lock;
};
# Tree-sitter grammars compile from C at build time. The
# default rust stdenv brings a cc, but we add pkg-config
# because a couple of transitive deps probe for it.
nativeBuildInputs = with pkgs; [
pkg-config
];
# `arboard` with `default-features = false` uses the bare
# X11 clipboard on Linux (libxcb), Cocoa on macOS (auto-
# linked), nothing on minimal targets. Conditionalised so
# the macOS build doesn't drag in xorg.
buildInputs = pkgs.lib.optionals pkgs.stdenv.isLinux [
pkgs.xorg.libxcb
];
# The 440-strong test suite is happy in a clean sandbox,
# but the panic-hardening crash test
# (`test_crash_writes_log_on_panic`) writes to a temp
# `~/.cache` path. The sandbox has no $HOME by default,
# so skip tests at flake-build time — `cargo test` on the
# host is the source of truth for CI anyway.
doCheck = false;
meta = with pkgs.lib; {
description = cargoToml.package.description;
homepage = "https://binvim.dev";
license = binvimLicense;
mainProgram = "binvim";
# Both binaries from the same crate land in $out/bin —
# `binvim` (the editor) and `binvim-install` (the
# toolchain installer). `nix run github:bgunnarsson/binvim`
# uses mainProgram for the default.
platforms = platforms.unix;
};
};
in
{
packages = {
default = binvim;
binvim = binvim;
};
# `nix run github:bgunnarsson/binvim` → opens the editor.
# `nix run github:bgunnarsson/binvim#binvim-install` → runs
# the toolchain installer. Both share the same derivation;
# only the `program` path differs. `meta` mirrors the package
# meta so `nix flake check` doesn't warn about missing fields.
apps = {
default = {
type = "app";
program = "${binvim}/bin/binvim";
meta = binvim.meta;
};
binvim = {
type = "app";
program = "${binvim}/bin/binvim";
meta = binvim.meta;
};
binvim-install = {
type = "app";
program = "${binvim}/bin/binvim-install";
meta = binvim.meta // {
description = "binvim toolchain installer (LSP servers + formatters)";
mainProgram = "binvim-install";
};
};
};
# `nix develop` drops you into a shell with the toolchain
# needed to hack on binvim itself (cargo + rustfmt +
# clippy + the tree-sitter C build deps).
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
rustc
cargo
rustfmt
clippy
pkg-config
] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [
pkgs.xorg.libxcb
];
};
}) // {
# System-agnostic outputs. Overlays let downstream system
# configs do `nixpkgs.overlays = [ inputs.binvim.overlays.default ];`
# and then reference `pkgs.binvim` like any other nixpkgs
# package — useful for NixOS/home-manager users who want
# binvim available as a global package alongside everything
# else they install.
overlays.default = final: prev: {
binvim = self.packages.${prev.stdenv.hostPlatform.system}.default;
};
};
}