flake.nix 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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/b/main.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 = ''bash devtools/dir-generator.sh tests/test_dir && echo "Dir generated"'';
  133. cargoTestOptions = opts: opts ++ ["--features nix"];
  134. inherit buildInputs;
  135. nativeBuildInputs = with pkgs; [git];
  136. };
  137. # TODO: add conditionally to checks.
  138. # Run `nix build .#trycmd` to run integration tests
  139. trycmd-local = naersk'.buildPackage {
  140. src = ./.;
  141. mode = "test";
  142. doCheck = true;
  143. # No reason to wait for release build
  144. release = false;
  145. # buildPhase files differ between dep and main phase
  146. singleStep = true;
  147. # set itests files creation date to unix epoch
  148. buildPhase = ''touch --date=@0 tests/itest/* && bash devtools/dir-generator.sh tests/test_dir'';
  149. cargoTestOptions = opts: opts ++ ["--features nix" "--features nix-local" "--features powertest"];
  150. inherit buildInputs;
  151. nativeBuildInputs = with pkgs; [git];
  152. };
  153. # Run `nix build .#trydump` to dump testing files
  154. trydump = naersk'.buildPackage {
  155. src = ./.;
  156. mode = "test";
  157. doCheck = true;
  158. # No reason to wait for release build
  159. release = false;
  160. # buildPhase files differ between dep and main phase
  161. singleStep = true;
  162. # set itests files creation date to unix epoch
  163. buildPhase = ''
  164. bash devtools/dir-generator.sh tests/test_dir
  165. touch --date=@0 tests/itest/*;
  166. rm tests/cmd/*.stdout || echo;
  167. rm tests/cmd/*.stderr || echo;
  168. touch --date=@0 tests/ptests/*;
  169. rm tests/ptests/*.stdout || echo;
  170. rm tests/ptests/*.stderr || echo;
  171. '';
  172. cargoTestOptions = opts: opts ++ ["--features nix" "--features nix-local" "--features powertest"];
  173. TRYCMD = "dump";
  174. postInstall = ''
  175. cp dump $out -r
  176. '';
  177. inherit buildInputs;
  178. nativeBuildInputs = with pkgs; [git];
  179. };
  180. };
  181. # For `nix develop`:
  182. devShells.default = pkgs.mkShell {
  183. inherit (self.checks.${system}.pre-commit-check) shellHook;
  184. nativeBuildInputs = with pkgs; [
  185. rustup
  186. toolchain
  187. just
  188. pandoc
  189. convco
  190. zip
  191. # For generating demo
  192. vhs
  193. powertest.packages.${pkgs.system}.default
  194. cargo-hack
  195. cargo-udeps
  196. cargo-outdated
  197. ];
  198. };
  199. # For `nix flake check`
  200. checks = {
  201. pre-commit-check = let
  202. # some treefmt formatters are not supported in pre-commit-hooks we filter them out for now.
  203. toFilter =
  204. # This is a nice hack to not have to manually filter we should keep in mind for a future refactor.
  205. # (builtins.attrNames pre-commit-hooks.packages.${system})
  206. ["yamlfmt"];
  207. filterFn = n: _v: (!builtins.elem n toFilter);
  208. treefmtFormatters = pkgs.lib.mapAttrs (_n: v: {inherit (v) enable;}) (pkgs.lib.filterAttrs filterFn (import ./treefmt.nix).programs);
  209. in
  210. pre-commit-hooks.lib.${system}.run {
  211. src = ./.;
  212. hooks =
  213. treefmtFormatters
  214. // {
  215. convco.enable = true; # not in treefmt
  216. };
  217. };
  218. formatting = treefmtEval.config.build.check self;
  219. build = packages.check;
  220. inherit
  221. (packages)
  222. default
  223. test
  224. trycmd
  225. ;
  226. lint = packages.clippy;
  227. };
  228. }
  229. );
  230. }