flake.nix 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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; 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 {
  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. buildInputs = buildInputs ++ (with pkgs; [zlib]);
  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 man/eza.1.md > man/eza.1
  52. pandoc --standalone -f markdown -t man man/eza_colors.5.md > man/eza_colors.5
  53. pandoc --standalone -f markdown -t man man/eza_colors-explanation.5.md > 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. # Run `nix build .#trydump` to dump testing files
  109. trydump = naersk'.buildPackage {
  110. src = ./.;
  111. mode = "test";
  112. doCheck = true;
  113. # No reason to wait for release build
  114. release = false;
  115. # buildPhase files differ between dep and main phase
  116. singleStep = true;
  117. # set itests files creation date to unix epoch
  118. buildPhase = ''touch --date=@0 tests/itest/*; rm tests/cmd/*.stdout || echo; rm tests/cmd/*.stderr || echo;'';
  119. cargoTestOptions = opts: opts ++ ["--features nix"];
  120. TRYCMD = "dump";
  121. postInstall = ''
  122. cp dump $out -r
  123. '';
  124. inherit buildInputs;
  125. };
  126. };
  127. # For `nix develop`:
  128. devShells.default = pkgs.mkShell {
  129. nativeBuildInputs = with pkgs; [rustup toolchain just pandoc convco];
  130. };
  131. # For `nix flake check`
  132. checks = {
  133. formatting = treefmtEval.config.build.check self;
  134. build = packages.check;
  135. test = packages.test;
  136. lint = packages.clippy;
  137. trycmd = packages.trycmd;
  138. };
  139. }
  140. );
  141. }