1
0

flake.nix 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. pre-commit-hooks = {
  21. url = "http://rime.cx/v1/github/semnix/pre-commit-hooks.nix.tar.gz";
  22. inputs.nixpkgs.follows = "nixpkgs";
  23. inputs.flake-utils.follows = "flake-utils";
  24. };
  25. advisory-db = {
  26. url = "github:rustsec/advisory-db";
  27. flake = false;
  28. };
  29. };
  30. outputs = {
  31. self,
  32. flake-utils,
  33. naersk,
  34. nixpkgs,
  35. treefmt-nix,
  36. rust-overlay,
  37. pre-commit-hooks,
  38. ...
  39. }:
  40. flake-utils.lib.eachDefaultSystem (
  41. system: let
  42. overlays = [(import rust-overlay)];
  43. pkgs = (import nixpkgs) {
  44. inherit system overlays;
  45. };
  46. toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
  47. naersk' = pkgs.callPackage naersk {
  48. cargo = toolchain;
  49. rustc = toolchain;
  50. clippy = toolchain;
  51. };
  52. treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
  53. buildInputs = with pkgs; [zlib] ++ lib.optionals stdenv.isDarwin [libiconv darwin.apple_sdk.frameworks.Security];
  54. in rec {
  55. # For `nix fmt`
  56. formatter = treefmtEval.config.build.wrapper;
  57. packages = {
  58. # For `nix build` `nix run`, & `nix profile install`:
  59. default = naersk'.buildPackage rec {
  60. pname = "eza";
  61. version = "latest";
  62. src = ./.;
  63. doCheck = true; # run `cargo test` on build
  64. inherit buildInputs;
  65. nativeBuildInputs = with pkgs; [cmake pkg-config installShellFiles pandoc];
  66. buildNoDefaultFeatures = true;
  67. buildFeatures = "git";
  68. postInstall = ''
  69. pandoc --standalone -f markdown -t man <(cat "man/eza.1.md" | sed "s/\$version/${version}/g") > man/eza.1
  70. pandoc --standalone -f markdown -t man <(cat "man/eza_colors.5.md" | sed "s/\$version/${version}/g") > man/eza_colors.5
  71. pandoc --standalone -f markdown -t man <(cat "man/eza_colors-explanation.5.md" | sed "s/\$version/${version}/g")> man/eza_colors-explanation.5
  72. installManPage man/eza.1 man/eza_colors.5 man/eza_colors-explanation.5
  73. installShellCompletion \
  74. --bash completions/bash/eza \
  75. --fish completions/fish/eza.fish \
  76. --zsh completions/zsh/_eza
  77. '';
  78. meta = with pkgs.lib; {
  79. description = "A modern, maintained replacement for ls";
  80. longDescription = ''
  81. eza is a modern replacement for ls. It uses colours for information by
  82. default, helping you distinguish between many types of files, such as
  83. whether you are the owner, or in the owning group. It also has extra
  84. features not present in the original ls, such as viewing the Git status
  85. for a directory, or recursing into directories with a tree view. eza is
  86. written in Rust, so it’s small, fast, and portable.
  87. '';
  88. homepage = "https://github.com/eza-community/eza";
  89. license = licenses.mit;
  90. mainProgram = "eza";
  91. maintainers = with maintainers; [cafkafk];
  92. };
  93. };
  94. # Run `nix build .#check` to check code
  95. check = naersk'.buildPackage {
  96. src = ./.;
  97. mode = "check";
  98. inherit buildInputs;
  99. };
  100. # Run `nix build .#test` to run tests
  101. test = naersk'.buildPackage {
  102. src = ./.;
  103. mode = "test";
  104. inherit buildInputs;
  105. };
  106. # Run `nix build .#clippy` to lint code
  107. clippy = naersk'.buildPackage {
  108. src = ./.;
  109. mode = "clippy";
  110. inherit buildInputs;
  111. };
  112. # Run `nix build .#trycmd` to run integration tests
  113. trycmd = naersk'.buildPackage {
  114. src = ./.;
  115. mode = "test";
  116. doCheck = true;
  117. # No reason to wait for release build
  118. release = false;
  119. # buildPhase files differ between dep and main phase
  120. singleStep = true;
  121. # set itests files creation date to unix epoch
  122. buildPhase = ''touch --date=@0 tests/itest/*'';
  123. cargoTestOptions = opts: opts ++ ["--features nix"];
  124. inherit buildInputs;
  125. };
  126. # TODO: add conditionally to checks.
  127. # Run `nix build .#trycmd` to run integration tests
  128. trycmd-local = naersk'.buildPackage {
  129. src = ./.;
  130. mode = "test";
  131. doCheck = true;
  132. # No reason to wait for release build
  133. release = false;
  134. # buildPhase files differ between dep and main phase
  135. singleStep = true;
  136. # set itests files creation date to unix epoch
  137. buildPhase = ''touch --date=@0 tests/itest/*'';
  138. cargoTestOptions = opts: opts ++ ["--features nix" "--features nix-local"];
  139. inherit buildInputs;
  140. };
  141. # Run `nix build .#trydump` to dump testing files
  142. trydump = 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 = ''touch --date=@0 tests/itest/*; rm tests/cmd/*.stdout || echo; rm tests/cmd/*.stderr || echo;'';
  152. cargoTestOptions = opts: opts ++ ["--features nix" "--features nix-local"];
  153. TRYCMD = "dump";
  154. postInstall = ''
  155. cp dump $out -r
  156. '';
  157. inherit buildInputs;
  158. };
  159. };
  160. # For `nix develop`:
  161. devShells.default = pkgs.mkShell {
  162. inherit (self.checks.${system}.pre-commit-check) shellHook;
  163. nativeBuildInputs = with pkgs; [
  164. toolchain
  165. rustup
  166. just
  167. pandoc
  168. convco
  169. zip
  170. cargo-hack
  171. cargo-udeps
  172. cargo-outdated
  173. ];
  174. };
  175. # For `nix flake check`
  176. checks = {
  177. pre-commit-check = pre-commit-hooks.lib.${system}.run {
  178. src = ./.;
  179. hooks = {
  180. convco.enable = true;
  181. alejandra.enable = true;
  182. deadnix.enable = true;
  183. rustfmt.enable = true;
  184. shellcheck.enable = true;
  185. taplo.enable = true;
  186. };
  187. };
  188. formatting = treefmtEval.config.build.check self;
  189. build = packages.check;
  190. default = packages.default;
  191. test = packages.test;
  192. lint = packages.clippy;
  193. trycmd = packages.trycmd;
  194. };
  195. }
  196. );
  197. }