flake.nix 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. bash devtools/dir-generator.sh tests/test_dir
  178. bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir
  179. touch --date=@0 tests/itest/*
  180. touch --date=@0 tests/ptests/*;
  181. fd -e stdout -e stderr -H -t file -X sed -i 's/[CWD]\//\/build\/source\//g'
  182. '';
  183. cargoTestOptions =
  184. opts:
  185. opts
  186. ++ [
  187. "--features nix"
  188. "--features nix-local"
  189. "--features powertest"
  190. ];
  191. inherit buildInputs;
  192. nativeBuildInputs = with pkgs; [ git ];
  193. };
  194. # Run `nix build .#trydump` to dump testing files
  195. trydump = naersk'.buildPackage rec {
  196. src = ./.;
  197. mode = "test";
  198. doCheck = true;
  199. # No reason to wait for release build
  200. release = false;
  201. # buildPhase files differ between dep and main phase
  202. singleStep = true;
  203. # set itests files creation date to unix epoch
  204. buildPhase = ''
  205. bash devtools/dir-generator.sh tests/test_dir
  206. bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir
  207. touch --date=@0 tests/itest/*;
  208. rm tests/cmd/*.stdout || echo;
  209. rm tests/cmd/*.stderr || echo;
  210. touch --date=@0 tests/ptests/*;
  211. rm tests/ptests/*.stdout || echo;
  212. rm tests/ptests/*.stderr || echo;
  213. '';
  214. cargoTestOptions =
  215. opts:
  216. opts
  217. ++ [
  218. "--features nix"
  219. "--features nix-local"
  220. "--features powertest"
  221. #"-F trycmd/debug"
  222. ];
  223. TRYCMD = "dump";
  224. postInstall = ''
  225. fd -e stdout -e stderr -H -t file -X sed -i 's/\/build\/source\//[CWD]\//g'
  226. cp dump $out -r
  227. '';
  228. inherit buildInputs;
  229. nativeBuildInputs = with pkgs; [
  230. fd
  231. gnused
  232. git
  233. ];
  234. };
  235. };
  236. # For `nix develop`:
  237. devShells.default = pkgs.mkShell {
  238. inherit (self.checks.${system}.pre-commit-check) shellHook;
  239. nativeBuildInputs =
  240. with pkgs;
  241. [
  242. cargo
  243. clippy
  244. rustup
  245. toolchain
  246. just
  247. pandoc
  248. convco
  249. zip
  250. reuse
  251. # For releases
  252. b3sum
  253. cargo-bump
  254. # For generating demo
  255. vhs
  256. powertest.packages.${pkgs.system}.default
  257. cargo-hack
  258. cargo-udeps
  259. cargo-outdated
  260. ]
  261. ++ darwinBuildInputs;
  262. };
  263. # For `nix flake check`
  264. checks = {
  265. pre-commit-check =
  266. let
  267. # some treefmt formatters are not supported in pre-commit-hooks we
  268. # filter them out for now.
  269. toFilter = [
  270. "yamlfmt"
  271. "nixfmt"
  272. "taplo"
  273. ];
  274. filterFn = n: _v: (!builtins.elem n toFilter);
  275. treefmtFormatters = pkgs.lib.mapAttrs (_n: v: { inherit (v) enable; }) (
  276. pkgs.lib.filterAttrs filterFn (import .config/treefmt.nix).programs
  277. );
  278. in
  279. pre-commit-hooks.lib.${system}.run {
  280. src = ./.;
  281. hooks = treefmtFormatters // {
  282. nixfmt-rfc-style.enable = true;
  283. convco.enable = true; # not in treefmt
  284. reuse = {
  285. enable = true;
  286. name = "reuse";
  287. entry = with pkgs; "${reuse}/bin/reuse lint";
  288. pass_filenames = false;
  289. };
  290. };
  291. };
  292. formatting = treefmtEval.config.build.check self;
  293. build = packages.check;
  294. inherit (packages)
  295. default
  296. test
  297. trycmd
  298. ;
  299. lint = packages.clippy;
  300. };
  301. }
  302. );
  303. }