|
4 | 4 | inputs = {
|
5 | 5 | flake-parts.url = "github:hercules-ci/flake-parts";
|
6 | 6 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
| 7 | + pre-commit-hooks-nix.url = "github:cachix/pre-commit-hooks.nix"; |
| 8 | + gitignore = { |
| 9 | + url = "github:hercules-ci/gitignore.nix"; |
| 10 | + inputs.nixpkgs.follows = "nixpkgs"; |
| 11 | + }; |
7 | 12 | };
|
8 | 13 |
|
9 |
| - outputs = inputs@{ flake-parts, ... }: |
10 |
| - flake-parts.lib.mkFlake { inherit inputs; } { |
| 14 | + outputs = inputs @ { |
| 15 | + flake-parts, |
| 16 | + pre-commit-hooks-nix, |
| 17 | + gitignore, |
| 18 | + ... |
| 19 | + }: |
| 20 | + flake-parts.lib.mkFlake {inherit inputs;} { |
11 | 21 | imports = [
|
| 22 | + inputs.pre-commit-hooks-nix.flakeModule |
| 23 | + ]; |
| 24 | + systems = [ |
| 25 | + "x86_64-linux" |
| 26 | + "aarch64-linux" |
| 27 | + "aarch64-darwin" |
| 28 | + "x86_64-darwin" |
12 | 29 | ];
|
13 |
| - systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; |
14 |
| - perSystem = { config, self', inputs', pkgs, system, ... }: { |
| 30 | + perSystem = { |
| 31 | + config, |
| 32 | + self', |
| 33 | + inputs', |
| 34 | + pkgs, |
| 35 | + system, |
| 36 | + ... |
| 37 | + }: let |
| 38 | + nodeMajorVersion = 18; |
| 39 | + runNode2Nix = pkgs.writeShellScriptBin "runNode2Nix" '' |
| 40 | + ${pkgs.node2nix}/bin/node2nix \ |
| 41 | + -${builtins.toString nodeMajorVersion} \ |
| 42 | + --input package.json \ |
| 43 | + --lock package-lock.json \ |
| 44 | + --node-env ./nix/node-env.nix \ |
| 45 | + --composition ./nix/default.nix \ |
| 46 | + --output ./nix/node-package.nix \ |
| 47 | + --development \ |
| 48 | + --include-peer-dependencies |
| 49 | + ''; |
| 50 | + nodejs = pkgs."nodejs-${builtins.toString nodeMajorVersion}_x"; |
| 51 | + node2nixOutput = import ./nix {inherit pkgs nodejs system;}; |
| 52 | + nodeDependencies = node2nixOutput.nodeDependencies; |
| 53 | + minAuth = pkgs.stdenv.mkDerivation { |
| 54 | + name = "MinAuth"; |
| 55 | + version = "0.1.0"; |
| 56 | + src = gitignore.lib.gitignoreSource ./.; |
| 57 | + buildInputs = [nodejs]; |
| 58 | + buildPhase = '' |
| 59 | + runHook preBuild |
| 60 | + ln -sf ${nodeDependencies}/lib/node_modules ./node_modules |
| 61 | + export PATH="${nodeDependencies}/bin:$PATH" |
| 62 | + npm run build |
| 63 | + runHook postBuild |
| 64 | + ''; |
| 65 | + installPhase = '' |
| 66 | + runHook preInstall |
| 67 | + mkdir -p $out |
| 68 | + cp package.json $out/package.json |
| 69 | + cp -r dist $out/dist |
| 70 | + ln -sf ${nodeDependencies}/lib/node_modules $out/node_modules |
| 71 | + runHook postInstall |
| 72 | + ''; |
| 73 | + }; |
| 74 | + in { |
| 75 | + pre-commit.settings.hooks = { |
| 76 | + eslint.enable = true; |
| 77 | + prettier.enable = true; |
| 78 | + alejandra.enable = true; |
| 79 | + }; |
15 | 80 | devShells.default = pkgs.mkShell {
|
16 |
| - packages = with pkgs; [ |
| 81 | + packages = [ |
17 | 82 | nodejs
|
18 |
| - nodePackages.typescript |
19 |
| - nodePackages.typescript-language-server |
| 83 | + config.pre-commit.settings.package |
| 84 | + runNode2Nix |
20 | 85 | ];
|
| 86 | + shellHook = config.pre-commit.installationScript; |
| 87 | + }; |
| 88 | + checks.default = self'.checks.pre-commit; |
| 89 | + packages = { |
| 90 | + inherit minAuth; |
| 91 | + default = minAuth; |
21 | 92 | };
|
22 | 93 | };
|
23 | 94 | flake = {
|
| 95 | + herculesCI.ciSystems = ["x86_64-linux"]; |
24 | 96 | };
|
25 | 97 | };
|
26 | 98 | }
|
0 commit comments