flake.nix 9.6 KB

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