flake.nix 9.6 KB

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