flake.nix 9.1 KB

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