1
0

flake.nix 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. # SPDX-FileCopyrightText: 2024 Christina Sørensen
  2. # SPDX-License-Identifier: EUPL-1.2
  3. #
  4. # SPDX-FileCopyrightText: 2014-2024 Christina Sørensen, eza contributors
  5. # SPDX-License-Identifier: MIT
  6. {
  7. description = "eza: a modern, maintained replacement for ls";
  8. inputs = {
  9. nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
  10. systems.url = "github:nix-systems/default";
  11. flake-utils = {
  12. url = "github:numtide/flake-utils";
  13. inputs = {
  14. systems.follows = "systems";
  15. };
  16. };
  17. naersk = {
  18. url = "github:nix-community/naersk";
  19. inputs.nixpkgs.follows = "nixpkgs";
  20. };
  21. rust-overlay = {
  22. url = "github:oxalica/rust-overlay";
  23. inputs = {
  24. nixpkgs.follows = "nixpkgs";
  25. };
  26. };
  27. treefmt-nix = {
  28. url = "github:numtide/treefmt-nix";
  29. inputs = {
  30. nixpkgs.follows = "nixpkgs";
  31. };
  32. };
  33. powertest = {
  34. url = "github:eza-community/powertest";
  35. inputs = {
  36. nixpkgs.follows = "nixpkgs";
  37. flake-utils.follows = "flake-utils";
  38. naersk.follows = "naersk";
  39. treefmt-nix.follows = "treefmt-nix";
  40. rust-overlay.follows = "rust-overlay";
  41. };
  42. };
  43. pre-commit-hooks = {
  44. url = "github:cachix/pre-commit-hooks.nix";
  45. inputs.nixpkgs.follows = "nixpkgs";
  46. };
  47. advisory-db = {
  48. url = "github:rustsec/advisory-db";
  49. flake = false;
  50. };
  51. };
  52. outputs =
  53. {
  54. self,
  55. flake-utils,
  56. naersk,
  57. nixpkgs,
  58. treefmt-nix,
  59. rust-overlay,
  60. powertest,
  61. pre-commit-hooks,
  62. ...
  63. }:
  64. flake-utils.lib.eachDefaultSystem (
  65. system:
  66. let
  67. overlays = [ (import rust-overlay) ];
  68. pkgs = (import nixpkgs) {
  69. inherit system overlays;
  70. };
  71. toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
  72. naersk' = pkgs.callPackage naersk {
  73. cargo = toolchain;
  74. rustc = toolchain;
  75. clippy = toolchain;
  76. };
  77. treefmtEval = treefmt-nix.lib.evalModule pkgs .config/treefmt.nix;
  78. darwinBuildInputs = pkgs.lib.optionals pkgs.stdenv.isDarwin [
  79. pkgs.libiconv
  80. pkgs.darwin.apple_sdk.frameworks.Security
  81. ];
  82. buildInputs = [ pkgs.zlib ] ++ darwinBuildInputs;
  83. in
  84. rec {
  85. # For `nix fmt`
  86. formatter = treefmtEval.config.build.wrapper;
  87. packages = {
  88. default = import ./nix/eza.nix { inherit pkgs naersk' buildInputs; };
  89. check = naersk'.buildPackage {
  90. inherit buildInputs;
  91. src = ./.;
  92. mode = "check";
  93. };
  94. test = naersk'.buildPackage {
  95. inherit buildInputs;
  96. src = ./.;
  97. mode = "test";
  98. };
  99. clippy = naersk'.buildPackage {
  100. inherit buildInputs;
  101. src = ./.;
  102. mode = "clippy";
  103. };
  104. }
  105. // (import ./nix/trycmd.nix { inherit pkgs naersk' buildInputs; });
  106. devShells.default = pkgs.mkShell {
  107. inherit (self.checks.${system}.pre-commit-check) shellHook;
  108. nativeBuildInputs =
  109. with pkgs;
  110. [
  111. # cargo
  112. # clippy
  113. rustup
  114. toolchain
  115. just
  116. pandoc
  117. convco
  118. zip
  119. reuse
  120. # For releases
  121. b3sum
  122. cargo-bump
  123. # For generating demo
  124. vhs
  125. powertest.packages.${pkgs.system}.default
  126. cargo-hack
  127. cargo-udeps
  128. cargo-outdated
  129. ]
  130. ++ darwinBuildInputs;
  131. };
  132. checks = {
  133. pre-commit-check =
  134. let
  135. toFilter = [
  136. "yamlfmt"
  137. "nixfmt"
  138. "taplo"
  139. "shellcheck" # this doesn't respect our excludes:w
  140. ];
  141. filterFn = n: _v: (!builtins.elem n toFilter);
  142. treefmtFormatters = pkgs.lib.mapAttrs (_n: v: { inherit (v) enable; }) (
  143. pkgs.lib.filterAttrs filterFn (import .config/treefmt.nix).programs
  144. );
  145. in
  146. pre-commit-hooks.lib.${system}.run {
  147. src = ./.;
  148. hooks = treefmtFormatters // {
  149. nixfmt-rfc-style.enable = true;
  150. convco.enable = true;
  151. reuse = {
  152. enable = true;
  153. name = "reuse";
  154. entry = with pkgs; "${reuse}/bin/reuse lint";
  155. pass_filenames = false;
  156. };
  157. };
  158. };
  159. formatting = treefmtEval.config.build.check self;
  160. build = packages.check;
  161. inherit (packages)
  162. default
  163. test
  164. trycmd
  165. ;
  166. lint = packages.clippy;
  167. };
  168. }
  169. );
  170. }