flake.nix 9.1 KB

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