flake.nix 9.5 KB

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