flake.nix 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. # SPDX-FileCopyrightText: 2024 Christina Sørensen
  2. # SPDX-License-Identifier: EUPL-1.2
  3. #
  4. # SPDX-FileCopyrightText: 2014-2024 Christina Sørensen, eza contributors
  5. # SPDX-License-Identifier: MIT
  6. {
  7. description = "eza: a modern, maintained replacement for ls";
  8. inputs = {
  9. nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
  10. systems.url = "github:nix-systems/default";
  11. flake-utils = {
  12. url = "github:numtide/flake-utils";
  13. inputs = {
  14. systems.follows = "systems";
  15. };
  16. };
  17. naersk = {
  18. url = "github:nix-community/naersk";
  19. inputs.nixpkgs.follows = "nixpkgs";
  20. };
  21. rust-overlay = {
  22. url = "github:oxalica/rust-overlay";
  23. inputs = {
  24. nixpkgs.follows = "nixpkgs";
  25. };
  26. };
  27. treefmt-nix = {
  28. url = "github:numtide/treefmt-nix";
  29. inputs = {
  30. nixpkgs.follows = "nixpkgs";
  31. };
  32. };
  33. powertest = {
  34. url = "github:eza-community/powertest";
  35. inputs = {
  36. nixpkgs.follows = "nixpkgs";
  37. flake-utils.follows = "flake-utils";
  38. naersk.follows = "naersk";
  39. treefmt-nix.follows = "treefmt-nix";
  40. rust-overlay.follows = "rust-overlay";
  41. };
  42. };
  43. pre-commit-hooks = {
  44. url = "github:cachix/pre-commit-hooks.nix";
  45. inputs.nixpkgs.follows = "nixpkgs";
  46. };
  47. advisory-db = {
  48. url = "github:rustsec/advisory-db";
  49. flake = false;
  50. };
  51. };
  52. outputs =
  53. {
  54. self,
  55. flake-utils,
  56. naersk,
  57. nixpkgs,
  58. treefmt-nix,
  59. rust-overlay,
  60. powertest,
  61. pre-commit-hooks,
  62. ...
  63. }:
  64. flake-utils.lib.eachDefaultSystem (
  65. system:
  66. let
  67. overlays = [ (import rust-overlay) ];
  68. pkgs = (import nixpkgs) {
  69. inherit system overlays;
  70. };
  71. toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
  72. naersk' = pkgs.callPackage naersk {
  73. cargo = toolchain;
  74. rustc = toolchain;
  75. clippy = toolchain;
  76. };
  77. treefmtEval = treefmt-nix.lib.evalModule pkgs .config/treefmt.nix;
  78. darwinBuildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin [
  79. pkgs.libiconv
  80. pkgs.darwin.apple_sdk.frameworks.Security
  81. ];
  82. buildInputs = [ pkgs.zlib ] ++ darwinBuildInputs;
  83. in
  84. rec {
  85. # For `nix fmt`
  86. formatter = treefmtEval.config.build.wrapper;
  87. packages = {
  88. # For `nix build` `nix run`, & `nix profile install`:
  89. default = naersk'.buildPackage rec {
  90. pname = "eza";
  91. version = "latest";
  92. src = ./.;
  93. doCheck = true; # run `cargo test` on build
  94. inherit buildInputs;
  95. nativeBuildInputs = with pkgs; [
  96. cmake
  97. pkg-config
  98. installShellFiles
  99. pandoc
  100. ];
  101. buildNoDefaultFeatures = true;
  102. buildFeatures = "git";
  103. postInstall = ''
  104. pandoc --standalone -f markdown -t man <(cat "man/eza.1.md" | sed "s/\$version/${version}/g") > man/eza.1
  105. pandoc --standalone -f markdown -t man <(cat "man/eza_colors.5.md" | sed "s/\$version/${version}/g") > man/eza_colors.5
  106. pandoc --standalone -f markdown -t man <(cat "man/eza_colors-explanation.5.md" | sed "s/\$version/${version}/g")> man/eza_colors-explanation.5
  107. installManPage man/eza.1 man/eza_colors.5 man/eza_colors-explanation.5
  108. installShellCompletion \
  109. --bash completions/bash/eza \
  110. --fish completions/fish/eza.fish \
  111. --zsh completions/zsh/_eza
  112. '';
  113. meta = with pkgs.lib; {
  114. description = "A modern, maintained replacement for ls";
  115. longDescription = ''
  116. eza is a modern replacement for ls. It uses colours for information by
  117. default, helping you distinguish between many types of files, such as
  118. whether you are the owner, or in the owning group. It also has extra
  119. features not present in the original ls, such as viewing the Git status
  120. for a directory, or recursing into directories with a tree view. eza is
  121. written in Rust, so it’s small, fast, and portable.
  122. '';
  123. homepage = "https://github.com/eza-community/eza";
  124. license = licenses.mit;
  125. mainProgram = "eza";
  126. maintainers = with maintainers; [ cafkafk ];
  127. };
  128. };
  129. # Run `nix build .#check` to check code
  130. check = naersk'.buildPackage {
  131. src = ./.;
  132. mode = "check";
  133. inherit buildInputs;
  134. };
  135. # Run `nix build .#test` to run tests
  136. test = naersk'.buildPackage {
  137. src = ./.;
  138. mode = "test";
  139. inherit buildInputs;
  140. };
  141. # Run `nix build .#clippy` to lint code
  142. clippy = naersk'.buildPackage {
  143. src = ./.;
  144. mode = "clippy";
  145. inherit buildInputs;
  146. };
  147. # Run `nix build .#trycmd` to run integration tests
  148. trycmd = naersk'.buildPackage {
  149. src = ./.;
  150. mode = "test";
  151. doCheck = true;
  152. # No reason to wait for release build
  153. release = false;
  154. # buildPhase files differ between dep and main phase
  155. singleStep = true;
  156. # generate testing files
  157. buildPhase = ''
  158. bash devtools/dir-generator.sh tests/test_dir && echo "Dir generated"
  159. bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir
  160. '';
  161. cargoTestOptions = opts: opts ++ [ "--features nix" ];
  162. inherit buildInputs;
  163. nativeBuildInputs = with pkgs; [ git ];
  164. };
  165. # TODO: add conditionally to checks.
  166. # Run `nix build .#trycmd` to run integration tests
  167. trycmd-local = naersk'.buildPackage {
  168. src = ./.;
  169. mode = "test";
  170. doCheck = true;
  171. # No reason to wait for release build
  172. release = false;
  173. # buildPhase files differ between dep and main phase
  174. singleStep = true;
  175. # set itests files creation date to unix epoch
  176. buildPhase = ''
  177. touch --date=@0 tests/itest/* && bash devtools/dir-generator.sh tests/test_dir
  178. bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir
  179. '';
  180. cargoTestOptions =
  181. opts:
  182. opts
  183. ++ [
  184. "--features nix"
  185. "--features nix-local"
  186. "--features powertest"
  187. ];
  188. inherit buildInputs;
  189. nativeBuildInputs = with pkgs; [ git ];
  190. };
  191. # Run `nix build .#trydump` to dump testing files
  192. trydump = naersk'.buildPackage rec {
  193. src = ./.;
  194. mode = "test";
  195. doCheck = true;
  196. # No reason to wait for release build
  197. release = false;
  198. # buildPhase files differ between dep and main phase
  199. singleStep = true;
  200. # set itests files creation date to unix epoch
  201. buildPhase = ''
  202. bash devtools/dir-generator.sh tests/test_dir
  203. bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir
  204. touch --date=@0 tests/itest/*;
  205. rm tests/cmd/*.stdout || echo;
  206. rm tests/cmd/*.stderr || echo;
  207. touch --date=@0 tests/ptests/*;
  208. rm tests/ptests/*.stdout || echo;
  209. rm tests/ptests/*.stderr || echo;
  210. '';
  211. cargoTestOptions =
  212. opts:
  213. opts
  214. ++ [
  215. "--features nix"
  216. "--features nix-local"
  217. "--features powertest"
  218. #"-F trycmd/debug"
  219. ];
  220. TRYCMD = "dump";
  221. postInstall = ''
  222. fd -e stdout -e stderr -H -t file -X sed -i 's/\/build\/source\//[CWD]\//g'
  223. cp dump $out -r
  224. '';
  225. inherit buildInputs;
  226. nativeBuildInputs = with pkgs; [
  227. fd
  228. gnused
  229. git
  230. ];
  231. };
  232. };
  233. # For `nix develop`:
  234. devShells.default = pkgs.mkShell {
  235. inherit (self.checks.${system}.pre-commit-check) shellHook;
  236. nativeBuildInputs =
  237. with pkgs;
  238. [
  239. toolchain
  240. rustup
  241. just
  242. pandoc
  243. convco
  244. zip
  245. reuse
  246. # For releases
  247. b3sum
  248. cargo-bump
  249. # For generating demo
  250. vhs
  251. powertest.packages.${pkgs.system}.default
  252. cargo-hack
  253. cargo-udeps
  254. cargo-outdated
  255. ]
  256. ++ darwinBuildInputs;
  257. };
  258. # For `nix flake check`
  259. checks = {
  260. pre-commit-check =
  261. let
  262. # some treefmt formatters are not supported in pre-commit-hooks we
  263. # filter them out for now.
  264. toFilter = [
  265. "yamlfmt"
  266. "nixfmt"
  267. ];
  268. filterFn = n: _v: (!builtins.elem n toFilter);
  269. treefmtFormatters = pkgs.lib.mapAttrs (_n: v: { inherit (v) enable; }) (
  270. pkgs.lib.filterAttrs filterFn (import .config/treefmt.nix).programs
  271. );
  272. in
  273. pre-commit-hooks.lib.${system}.run {
  274. src = ./.;
  275. hooks = treefmtFormatters // {
  276. nixfmt-rfc-style.enable = true;
  277. convco.enable = true; # not in treefmt
  278. reuse = {
  279. enable = true;
  280. name = "reuse";
  281. entry = with pkgs; "${reuse}/bin/reuse lint";
  282. pass_filenames = false;
  283. };
  284. };
  285. };
  286. formatting = treefmtEval.config.build.check self;
  287. build = packages.check;
  288. inherit (packages)
  289. default
  290. test
  291. trycmd
  292. ;
  293. lint = packages.clippy;
  294. };
  295. }
  296. );
  297. }