|
5 | 5 | flake-parts.url = "github:hercules-ci/flake-parts"; |
6 | 6 | nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; |
7 | 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 | + }; |
8 | 12 | }; |
9 | 13 |
|
10 | 14 | outputs = inputs @ { |
11 | 15 | flake-parts, |
12 | 16 | pre-commit-hooks-nix, |
| 17 | + gitignore, |
13 | 18 | ... |
14 | 19 | }: |
15 | 20 | flake-parts.lib.mkFlake {inherit inputs;} { |
16 | 21 | imports = [ |
17 | 22 | inputs.pre-commit-hooks-nix.flakeModule |
18 | 23 | ]; |
19 | | - systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"]; |
| 24 | + systems = [ |
| 25 | + "x86_64-linux" |
| 26 | + "aarch64-linux" |
| 27 | + "aarch64-darwin" |
| 28 | + "x86_64-darwin" |
| 29 | + ]; |
20 | 30 | perSystem = { |
21 | 31 | config, |
22 | 32 | self', |
23 | 33 | inputs', |
24 | 34 | pkgs, |
25 | 35 | system, |
26 | 36 | ... |
27 | | - }: { |
| 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 { |
28 | 75 | pre-commit.settings.hooks = { |
29 | 76 | eslint.enable = true; |
30 | 77 | prettier.enable = true; |
31 | 78 | alejandra.enable = true; |
32 | 79 | }; |
33 | 80 | devShells.default = pkgs.mkShell { |
34 | | - packages = with pkgs; [ |
| 81 | + packages = [ |
35 | 82 | nodejs |
36 | | - nodePackages.typescript |
37 | | - nodePackages.typescript-language-server |
38 | 83 | config.pre-commit.settings.package |
| 84 | + runNode2Nix |
39 | 85 | ]; |
40 | 86 | shellHook = config.pre-commit.installationScript; |
41 | 87 | }; |
| 88 | + checks.default = self'.checks.pre-commit; |
| 89 | + packages = { |
| 90 | + inherit minAuth; |
| 91 | + default = minAuth; |
| 92 | + }; |
42 | 93 | }; |
43 | 94 | flake = { |
44 | 95 | }; |
|
0 commit comments