flake.nix
140 lines · 4181 bytes
1{
2 description = "iamb";
3 nixConfig.bash-prompt = "\[nix-develop\]$ ";
4
5 inputs = {
6 nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
7 flake-utils.url = "github:numtide/flake-utils";
8 crane.url = "github:ipetkov/crane";
9 fenix = {
10 url = "github:nix-community/fenix";
11 inputs.nixpkgs.follows = "nixpkgs";
12 };
13 };
14
15 outputs =
16 {
17 self,
18 nixpkgs,
19 crane,
20 flake-utils,
21 fenix,
22 ...
23 }:
24 flake-utils.lib.eachDefaultSystem (
25 system:
26 let
27 pkgs = nixpkgs.legacyPackages.${system};
28 inherit (pkgs) lib;
29
30 rustToolchain = fenix.packages.${system}.fromToolchainFile {
31 file = ./rust-toolchain.toml;
32 # When the file changes, this hash must be updated.
33 sha256 = "sha256-SBKjxhC6zHTu0SyJwxLlQHItzMzYZ71VCWQC2hOzpRY=";
34 };
35
36 # Nightly toolchain for rustfmt (pinned to current flake lock)
37 # Note that the github CI uses "current nightly" for formatting, it 's not pinned.
38 rustNightly = fenix.packages.${system}.latest;
39
40 craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
41 craneLibNightly = (crane.mkLib pkgs).overrideToolchain rustNightly.toolchain;
42
43 src = lib.fileset.toSource {
44 root = ./.;
45 fileset = lib.fileset.unions [
46 (craneLib.fileset.commonCargoSources ./.)
47 ./src/windows/welcome.md
48
49 ./docs/iamb.1
50 ./docs/iamb.5
51 ./docs/iamb.svg
52 ./docs/iamb.metainfo.xml
53 ./iamb.desktop
54 ];
55 };
56
57 commonArgs = rec {
58 inherit src;
59 strictDeps = true;
60 pname = "iamb";
61 version = self.shortRev or self.dirtyShortRev;
62
63 VERGEN_GIT_SHA = version;
64 };
65
66 # Build *just* the cargo dependencies, so we can reuse
67 # all of that work (e.g. via cachix) when running in CI
68 cargoArtifacts = craneLib.buildDepsOnly commonArgs;
69
70 # Build the actual crate
71 iamb = craneLib.buildPackage (commonArgs // {
72 inherit cargoArtifacts;
73
74 nativeBuildInputs = [ pkgs.installShellFiles ];
75 postInstall = ''
76 mkdir -p completions
77 ./target/release/iamb --completions zsh > completions/_iamb
78 ./target/release/iamb --completions bash > completions/iamb.bash
79 ./target/release/iamb --completions fish > completions/iamb.fish
80 installShellCompletion --cmd iamb completions/*
81
82 installManPage $src/docs/iamb.{1,5}
83 install -D $src/docs/iamb.svg -t $out/share/icons/hicolor/scalable/apps
84 install -D $src/docs/iamb.metainfo.xml $out/share/appdata/chat.iamb.iamb.appdata.xml
85 install -D $src/iamb.desktop -t $out/share/applications
86 '';
87
88 meta = {
89 description = "Matrix client for Vim addicts";
90 mainProgram = "iamb";
91 homepage = "https://github.com/ulyssa/iamb";
92 license = lib.licenses.asl20;
93 };
94 });
95 in
96 {
97 checks = {
98 # Build the crate as part of `nix flake check`
99 inherit iamb;
100
101 iamb-clippy = craneLib.cargoClippy (commonArgs // {
102 inherit cargoArtifacts;
103 cargoClippyExtraArgs = "--all-targets -- --deny warnings";
104 });
105
106 iamb-fmt = craneLibNightly.cargoFmt {
107 inherit src;
108 };
109
110 iamb-nextest = craneLib.cargoNextest (commonArgs // {
111 inherit cargoArtifacts;
112 partitions = 1;
113 partitionType = "count";
114 });
115 };
116
117 packages.default = iamb;
118
119 apps.default = flake-utils.lib.mkApp {
120 drv = iamb;
121 };
122
123 devShells.default = craneLib.devShell {
124 # Inherit inputs from checks
125 checks = self.checks.${system};
126
127 packages = with pkgs; [
128 cargo-tarpaulin
129 cargo-watch
130 sqlite
131 ];
132
133 shellHook = ''
134 # Prepend nightly rustfmt to PATH.
135 export PATH="${rustNightly.rustfmt}/bin:$PATH"
136 '';
137 };
138 }
139 );
140}