flake.nix 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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 = "git";
  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. for page in eza.1 eza_colors.5 eza_colors-explanation.5; do
  105. sed "s/\$version/${version}/g" "man/$page.md" |
  106. pandoc --standalone -f markdown -t man >"man/$page"
  107. done
  108. installManPage man/eza.1 man/eza_colors.5 man/eza_colors-explanation.5
  109. installShellCompletion \
  110. --bash completions/bash/eza \
  111. --fish completions/fish/eza.fish \
  112. --zsh completions/zsh/_eza
  113. '';
  114. meta = with pkgs.lib; {
  115. description = "A modern, maintained replacement for ls";
  116. longDescription = ''
  117. eza is a modern replacement for ls. It uses colours for information by
  118. default, helping you distinguish between many types of files, such as
  119. whether you are the owner, or in the owning group. It also has extra
  120. features not present in the original ls, such as viewing the Git status
  121. for a directory, or recursing into directories with a tree view. eza is
  122. written in Rust, so it’s small, fast, and portable.
  123. '';
  124. homepage = "https://github.com/eza-community/eza";
  125. license = licenses.mit;
  126. mainProgram = "eza";
  127. maintainers = with maintainers; [ cafkafk ];
  128. };
  129. };
  130. # Run `nix build .#check` to check code
  131. check = naersk'.buildPackage {
  132. src = ./.;
  133. mode = "check";
  134. inherit buildInputs;
  135. };
  136. # Run `nix build .#test` to run tests
  137. test = naersk'.buildPackage {
  138. src = ./.;
  139. mode = "test";
  140. inherit buildInputs;
  141. };
  142. # Run `nix build .#clippy` to lint code
  143. clippy = naersk'.buildPackage {
  144. src = ./.;
  145. mode = "clippy";
  146. inherit buildInputs;
  147. };
  148. # Run `nix build .#trycmd` to run integration tests
  149. trycmd = naersk'.buildPackage {
  150. src = ./.;
  151. mode = "test";
  152. doCheck = true;
  153. # No reason to wait for release build
  154. release = false;
  155. # buildPhase files differ between dep and main phase
  156. singleStep = true;
  157. # generate testing files
  158. buildPhase = ''
  159. bash devtools/dir-generator.sh tests/test_dir && echo "Dir generated"
  160. bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir
  161. '';
  162. cargoTestOptions = opts: opts ++ [ "--features nix" ];
  163. inherit buildInputs;
  164. nativeBuildInputs = with pkgs; [ git ];
  165. };
  166. # TODO: add conditionally to checks.
  167. # Run `nix build .#trycmd` to run integration tests
  168. trycmd-local = naersk'.buildPackage {
  169. src = ./.;
  170. mode = "test";
  171. doCheck = true;
  172. # No reason to wait for release build
  173. release = false;
  174. # buildPhase files differ between dep and main phase
  175. singleStep = true;
  176. # set itests files creation date to unix epoch
  177. buildPhase = ''
  178. bash devtools/dir-generator.sh tests/test_dir
  179. bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir
  180. touch --date=@0 tests/itest/*
  181. touch --date=@0 tests/ptests/*;
  182. fd -e stdout -e stderr -H -t file -X sed -i 's/[CWD]\//\/build\/source\//g'
  183. '';
  184. cargoTestOptions =
  185. opts:
  186. opts
  187. ++ [
  188. "--features nix"
  189. "--features nix-local"
  190. "--features powertest"
  191. ];
  192. inherit buildInputs;
  193. nativeBuildInputs = with pkgs; [ git ];
  194. };
  195. # Run `nix build .#trydump` to dump testing files
  196. trydump = naersk'.buildPackage rec {
  197. src = ./.;
  198. mode = "test";
  199. doCheck = true;
  200. # No reason to wait for release build
  201. release = false;
  202. # buildPhase files differ between dep and main phase
  203. singleStep = true;
  204. # set itests files creation date to unix epoch
  205. buildPhase = ''
  206. bash devtools/dir-generator.sh tests/test_dir
  207. bash devtools/generate-timestamp-test-dir.sh tests/timestamp_test_dir
  208. touch --date=@0 tests/itest/*;
  209. rm tests/cmd/*.stdout || echo;
  210. rm tests/cmd/*.stderr || echo;
  211. touch --date=@0 tests/ptests/*;
  212. rm tests/ptests/*.stdout || echo;
  213. rm tests/ptests/*.stderr || echo;
  214. '';
  215. cargoTestOptions =
  216. opts:
  217. opts
  218. ++ [
  219. "--features nix"
  220. "--features nix-local"
  221. "--features powertest"
  222. #"-F trycmd/debug"
  223. ];
  224. TRYCMD = "dump";
  225. postInstall = ''
  226. fd -e stdout -e stderr -H -t file -X sed -i 's/\/build\/source\//[CWD]\//g'
  227. cp dump $out -r
  228. '';
  229. inherit buildInputs;
  230. nativeBuildInputs = with pkgs; [
  231. fd
  232. gnused
  233. git
  234. ];
  235. };
  236. };
  237. # For `nix develop`:
  238. devShells.default = pkgs.mkShell {
  239. inherit (self.checks.${system}.pre-commit-check) shellHook;
  240. nativeBuildInputs =
  241. with pkgs;
  242. [
  243. # cargo
  244. # clippy
  245. rustup
  246. toolchain
  247. just
  248. pandoc
  249. convco
  250. zip
  251. reuse
  252. # For releases
  253. b3sum
  254. cargo-bump
  255. # For generating demo
  256. vhs
  257. powertest.packages.${pkgs.system}.default
  258. cargo-hack
  259. cargo-udeps
  260. cargo-outdated
  261. ]
  262. ++ darwinBuildInputs;
  263. };
  264. # For `nix flake check`
  265. checks = {
  266. pre-commit-check =
  267. let
  268. # some treefmt formatters are not supported in pre-commit-hooks we
  269. # filter them out for now.
  270. toFilter = [
  271. "yamlfmt"
  272. "nixfmt"
  273. "taplo"
  274. ];
  275. filterFn = n: _v: (!builtins.elem n toFilter);
  276. treefmtFormatters = pkgs.lib.mapAttrs (_n: v: { inherit (v) enable; }) (
  277. pkgs.lib.filterAttrs filterFn (import .config/treefmt.nix).programs
  278. );
  279. in
  280. pre-commit-hooks.lib.${system}.run {
  281. src = ./.;
  282. hooks = treefmtFormatters // {
  283. nixfmt-rfc-style.enable = true;
  284. convco.enable = true; # not in treefmt
  285. reuse = {
  286. enable = true;
  287. name = "reuse";
  288. entry = with pkgs; "${reuse}/bin/reuse lint";
  289. pass_filenames = false;
  290. };
  291. };
  292. };
  293. formatting = treefmtEval.config.build.check self;
  294. build = packages.check;
  295. inherit (packages)
  296. default
  297. test
  298. trycmd
  299. ;
  300. lint = packages.clippy;
  301. };
  302. }
  303. );
  304. }