flake.nix 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. {
  2. description = "The EZA flake for developing and releasing (soon)";
  3. inputs = {
  4. flake-utils.url = "github:numtide/flake-utils";
  5. naersk.url = "github:nix-community/naersk";
  6. nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
  7. treefmt-nix.url = "github:numtide/treefmt-nix";
  8. rust-overlay.url = "github:oxalica/rust-overlay";
  9. };
  10. outputs = {
  11. self,
  12. flake-utils,
  13. naersk,
  14. nixpkgs,
  15. treefmt-nix,
  16. rust-overlay,
  17. }:
  18. flake-utils.lib.eachDefaultSystem (
  19. system: let
  20. overlays = [(import rust-overlay)];
  21. pkgs = (import nixpkgs) {
  22. inherit system overlays;
  23. };
  24. toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
  25. naersk' = pkgs.callPackage naersk {
  26. cargo = toolchain;
  27. rustc = toolchain;
  28. clippy = toolchain;
  29. };
  30. treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
  31. buildInputs = with pkgs; [zlib] ++ lib.optionals stdenv.isDarwin [libiconv darwin.apple_sdk.frameworks.Security];
  32. in rec {
  33. # For `nix fmt`
  34. formatter = treefmtEval.config.build.wrapper;
  35. packages = {
  36. # For `nix build` `nix run`, & `nix profile install`:
  37. default = naersk'.buildPackage rec {
  38. pname = "eza";
  39. version = "latest";
  40. src = ./.;
  41. doCheck = true; # run `cargo test` on build
  42. # buildInputs = with pkgs; [ zlib ]
  43. # ++ lib.optionals stdenv.isDarwin [ libiconv Security ];
  44. inherit buildInputs;
  45. nativeBuildInputs = with pkgs; [cmake pkg-config installShellFiles pandoc];
  46. buildNoDefaultFeatures = true;
  47. # buildFeatures = lib.optional gitSupport "git";
  48. buildFeatures = "git";
  49. # outputs = [ "out" "man" ];
  50. postInstall = ''
  51. pandoc --standalone -f markdown -t man <(cat "man/eza.1.md" | sed "s/\$version/${version}/g") > man/eza.1
  52. pandoc --standalone -f markdown -t man <(cat "man/eza_colors.5.md" | sed "s/\$version/${version}/g") > man/eza_colors.5
  53. pandoc --standalone -f markdown -t man <(cat "man/eza_colors-explanation.5.md" | sed "s/\$version/${version}/g")> man/eza_colors-explanation.5
  54. installManPage man/eza.1 man/eza_colors.5 man/eza_colors-explanation.5
  55. installShellCompletion \
  56. --bash completions/bash/eza \
  57. --fish completions/fish/eza.fish \
  58. --zsh completions/zsh/_eza
  59. '';
  60. meta = with pkgs.lib; {
  61. description = "A modern, maintained replacement for ls";
  62. longDescription = ''
  63. eza is a modern replacement for ls. It uses colours for information by
  64. default, helping you distinguish between many types of files, such as
  65. whether you are the owner, or in the owning group. It also has extra
  66. features not present in the original ls, such as viewing the Git status
  67. for a directory, or recursing into directories with a tree view. eza is
  68. written in Rust, so it’s small, fast, and portable.
  69. '';
  70. homepage = "https://github.com/eza-community/eza";
  71. license = licenses.mit;
  72. mainProgram = "eza";
  73. maintainers = with maintainers; [cafkafk];
  74. };
  75. };
  76. # Run `nix build .#check` to check code
  77. check = naersk'.buildPackage {
  78. src = ./.;
  79. mode = "check";
  80. inherit buildInputs;
  81. };
  82. # Run `nix build .#test` to run tests
  83. test = naersk'.buildPackage {
  84. src = ./.;
  85. mode = "test";
  86. inherit buildInputs;
  87. };
  88. # Run `nix build .#clippy` to lint code
  89. clippy = naersk'.buildPackage {
  90. src = ./.;
  91. mode = "clippy";
  92. inherit buildInputs;
  93. };
  94. # Run `nix build .#trycmd` to run integration tests
  95. trycmd = naersk'.buildPackage {
  96. src = ./.;
  97. mode = "test";
  98. doCheck = true;
  99. # No reason to wait for release build
  100. release = false;
  101. # buildPhase files differ between dep and main phase
  102. singleStep = true;
  103. # set itests files creation date to unix epoch
  104. buildPhase = ''touch --date=@0 tests/itest/*'';
  105. cargoTestOptions = opts: opts ++ ["--features nix"];
  106. inherit buildInputs;
  107. };
  108. # TODO: add conditionally to checks.
  109. # Run `nix build .#trycmd` to run integration tests
  110. trycmd-local = naersk'.buildPackage {
  111. src = ./.;
  112. mode = "test";
  113. doCheck = true;
  114. # No reason to wait for release build
  115. release = false;
  116. # buildPhase files differ between dep and main phase
  117. singleStep = true;
  118. # set itests files creation date to unix epoch
  119. buildPhase = ''touch --date=@0 tests/itest/*'';
  120. cargoTestOptions = opts: opts ++ ["--features nix" "--features nix-local"];
  121. inherit buildInputs;
  122. };
  123. # Run `nix build .#trydump` to dump testing files
  124. trydump = naersk'.buildPackage {
  125. src = ./.;
  126. mode = "test";
  127. doCheck = true;
  128. # No reason to wait for release build
  129. release = false;
  130. # buildPhase files differ between dep and main phase
  131. singleStep = true;
  132. # set itests files creation date to unix epoch
  133. buildPhase = ''touch --date=@0 tests/itest/*; rm tests/cmd/*.stdout || echo; rm tests/cmd/*.stderr || echo;'';
  134. cargoTestOptions = opts: opts ++ ["--features nix" "--features nix-local"];
  135. TRYCMD = "dump";
  136. postInstall = ''
  137. cp dump $out -r
  138. '';
  139. inherit buildInputs;
  140. };
  141. };
  142. # For `nix develop`:
  143. devShells.default = pkgs.mkShell {
  144. nativeBuildInputs = with pkgs; [rustup toolchain just pandoc convco];
  145. };
  146. # For `nix flake check`
  147. checks = {
  148. formatting = treefmtEval.config.build.check self;
  149. build = packages.check;
  150. default = packages.default;
  151. test = packages.test;
  152. lint = packages.clippy;
  153. trycmd = packages.trycmd;
  154. };
  155. }
  156. );
  157. }