diff --git a/.envrc b/.envrc index 3550a30..4c6160f 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use flake +use flake ./dev diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index afdb7b2..3594b62 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -21,4 +21,4 @@ jobs: steps: - uses: actions/checkout@v5 - uses: cachix/install-nix-action@v31 - - run: nix flake check + - run: nix flake check ./dev diff --git a/.vscode/settings.json b/.vscode/settings.json index 672e522..0e82542 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { "[nix]": { - "editor.defaultFormatter": "brettm12345.nixfmt-vscode" + "editor.defaultFormatter": "VanCoding.vscode-treefmt-nix" } } diff --git a/dev/checks.nix b/dev/checks.nix new file mode 100644 index 0000000..92dd442 --- /dev/null +++ b/dev/checks.nix @@ -0,0 +1,80 @@ +{ + perSystem = + { pkgs, ... }: + let + prisma-factory = import ../prisma.nix; + yarn-v1 = pkgs.writeShellApplication { + name = "yarn-v1"; + checkPhase = ""; + runtimeInputs = [ pkgs.yarn ]; + text = "yarn $@"; + }; + yarn-berry = pkgs.writeShellApplication { + name = "yarn-berry"; + checkPhase = ""; + runtimeInputs = [ pkgs.yarn-berry ]; + text = "yarn $@"; + }; + in + { + checks = + (pkgs.callPackages ../tests.nix { + fetcherMode = "new"; + inherit + pkgs + prisma-factory + yarn-v1 + yarn-berry + ; + }) + // (pkgs.callPackages ../tests.nix { + fetcherMode = "legacy"; + inherit + pkgs + prisma-factory + yarn-v1 + yarn-berry + ; + }) + // { + fetcher-assert-npm = + let + # force download debian for consistent hash across systems + binaryTargetBySystem = { + x86_64-linux = "debian"; + aarch64-linux = "debian"; + x86_64-darwin = "debian"; + aarch64-darwin = "debian"; + }; + prisma-legacy = prisma-factory { + inherit pkgs binaryTargetBySystem; + hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; + }; + prisma-new = + lockName: lockFile: + prisma-factory { + inherit pkgs binaryTargetBySystem; + hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; + ${lockName} = lockFile; + }; + in + assert + (prisma-legacy.fromNpmLock ../npm/package-lock.json).env + == (prisma-new "npmLock" ../npm/package-lock.json).env; + pkgs.hello; + prisma-next = + (prisma-factory { + pkgs = pkgs; + versionString = "6.20.0-16.next-0c19ccc313cf9911a90d99d2ac2eb0280c76c513"; + hash = + { + x86_64-linux = "sha256-JWX+N/mmp9uJLcv4XFbQ3yg34fFf2BLIUpOLrrfTjEM="; + x86_64-darwin = "sha256-WNwFOoeDOebbfAh4y/NvZCyE9otaJdg2hHb4ifEFD+Y="; + aarch64-linux = "sha256-f9FuPZaGx0FwKo4pA9f8g82MTcAzYLwWslxjb7oqk6E="; + aarch64-darwin = "sha256-NMI+JcP3epBO3V37D19TDgzivMnPekgrYqUrXB6qNV0="; + } + .${pkgs.system}; + }).package; + }; + }; +} diff --git a/dev/flake.lock b/dev/flake.lock new file mode 100644 index 0000000..0ffbdbb --- /dev/null +++ b/dev/flake.lock @@ -0,0 +1,82 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1775087534, + "narHash": "sha256-91qqW8lhL7TLwgQWijoGBbiD4t7/q75KTi8NxjVmSmA=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "3107b77cd68437b9a76194f0f7f9c55f2329ca5b", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1775095191, + "narHash": "sha256-CsqRiYbgQyv01LS0NlC7shwzhDhjNDQSrhBX8VuD3nM=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "106eb93cbb9d4e4726bf6bc367a3114f7ed6b32f", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1774748309, + "narHash": "sha256-+U7gF3qxzwD5TZuANzZPeJTZRHS29OFQgkQ2kiTJBIQ=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "333c4e0545a6da976206c74db8773a1645b5870a", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1775125835, + "narHash": "sha256-2qYcPgzFhnQWchHo0SlqLHrXpux5i6ay6UHA+v2iH4U=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "75925962939880974e3ab417879daffcba36c4a3", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/dev/flake.nix b/dev/flake.nix new file mode 100644 index 0000000..fea8285 --- /dev/null +++ b/dev/flake.nix @@ -0,0 +1,23 @@ +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + treefmt-nix.url = "github:numtide/treefmt-nix"; + treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; + }; + outputs = + inputs: + inputs.flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + imports = [ + ./treefmt.nix + ./shell.nix + ./checks.nix + ]; + }; +} diff --git a/dev/shell.nix b/dev/shell.nix new file mode 100644 index 0000000..71afca7 --- /dev/null +++ b/dev/shell.nix @@ -0,0 +1,15 @@ +{ + perSystem = + { pkgs, config, ... }: + { + devShells.default = pkgs.mkShell { + buildInputs = [ + pkgs.nodejs_24 + pkgs.pnpm + pkgs.bun + pkgs.stdenv.cc.cc.lib + config.treefmt.build.wrapper + ]; + }; + }; +} diff --git a/dev/treefmt.nix b/dev/treefmt.nix new file mode 100644 index 0000000..928e039 --- /dev/null +++ b/dev/treefmt.nix @@ -0,0 +1,7 @@ +{ inputs, ... }: +{ + imports = [ inputs.treefmt-nix.flakeModule ]; + perSystem.treefmt = { + programs.nixfmt.enable = true; + }; +} diff --git a/flake.lock b/flake.lock index 3665d48..5999137 100644 --- a/flake.lock +++ b/flake.lock @@ -1,81 +1,6 @@ { "nodes": { - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1731533236, - "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1738703096, - "narHash": "sha256-1MABVDwNpAUrUDvyM6PlHlAB1eTWAX0eNYCzdsZ54NI=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "f7384aacd0ecd28681a99269ac0dff2c3a805d63", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixpkgs-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs", - "treefmt-nix": "treefmt-nix" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - }, - "treefmt-nix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ] - }, - "locked": { - "lastModified": 1738070913, - "narHash": "sha256-j6jC12vCFsTGDmY2u1H12lMr62fnclNjuCtAdF1a4Nk=", - "owner": "numtide", - "repo": "treefmt-nix", - "rev": "bebf27d00f7d10ba75332a0541ac43676985dea3", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "treefmt-nix", - "type": "github" - } - } + "root": {} }, "root": "root", "version": 7 diff --git a/flake.nix b/flake.nix index bde0b4b..2939b73 100644 --- a/flake.nix +++ b/flake.nix @@ -1,138 +1,7 @@ { - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - flake-utils.url = "github:numtide/flake-utils"; - treefmt-nix.url = "github:numtide/treefmt-nix"; - treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; - }; - outputs = - { - self, - nixpkgs, - flake-utils, - treefmt-nix, - }: - let + outputs = inputs: { + lib = { prisma-factory = import ./prisma.nix; - in - flake-utils.lib.eachDefaultSystem ( - system: - let - pkgs = nixpkgs.legacyPackages.${system}; - - yarn-v1 = pkgs.writeShellApplication { - name = "yarn-v1"; - checkPhase = ""; - runtimeInputs = [ pkgs.yarn ]; - text = "yarn $@"; - }; - yarn-berry = pkgs.writeShellApplication { - name = "yarn-berry"; - checkPhase = ""; - runtimeInputs = [ pkgs.yarn-berry ]; - text = "yarn $@"; - }; - treefmt = treefmt-nix.lib.evalModule pkgs { - # nixfmt is nixfmt-rfc-style - programs.nixfmt.enable = true; - }; - in - { - formatter = treefmt.config.build.wrapper; - checks = - (pkgs.callPackages ./tests.nix { - fetcherMode = "new"; - inherit - pkgs - prisma-factory - yarn-v1 - yarn-berry - ; - }) - // (pkgs.callPackages ./tests.nix { - fetcherMode = "legacy"; - inherit - pkgs - prisma-factory - yarn-v1 - yarn-berry - ; - }) - // { - format = treefmt.config.build.check self; - fetcher-assert-npm = - let - # force download debian for consistent hash across systems - binaryTargetBySystem = { - x86_64-linux = "debian"; - aarch64-linux = "debian"; - x86_64-darwin = "debian"; - aarch64-darwin = "debian"; - }; - prisma-legacy = prisma-factory { - inherit pkgs binaryTargetBySystem; - hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; - }; - prisma-new = - lockName: lockFile: - prisma-factory { - inherit pkgs binaryTargetBySystem; - hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; - ${lockName} = lockFile; - }; - in - assert - (prisma-legacy.fromNpmLock ./npm/package-lock.json).env - == (prisma-new "npmLock" ./npm/package-lock.json).env; - pkgs.hello; - prisma-next = - (self.lib.prisma-factory { - pkgs = pkgs; - versionString = "6.20.0-16.next-0c19ccc313cf9911a90d99d2ac2eb0280c76c513"; - hash = - { - x86_64-linux = "sha256-JWX+N/mmp9uJLcv4XFbQ3yg34fFf2BLIUpOLrrfTjEM="; - x86_64-darwin = "sha256-WNwFOoeDOebbfAh4y/NvZCyE9otaJdg2hHb4ifEFD+Y="; - aarch64-linux = "sha256-f9FuPZaGx0FwKo4pA9f8g82MTcAzYLwWslxjb7oqk6E="; - aarch64-darwin = "sha256-NMI+JcP3epBO3V37D19TDgzivMnPekgrYqUrXB6qNV0="; - } - .${pkgs.system}; - }).package; - }; - packages.default = - (prisma-factory { - inherit pkgs; - hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; - versionString = "5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e"; - }).package; - devShells.default = - let - prisma = ( - prisma-factory { - inherit pkgs; - hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; - versionString = "5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e"; - } - ); - in - pkgs.mkShell { - buildInputs = [ - pkgs.nodejs-18_x - pkgs.pnpm - pkgs.bun - pkgs.stdenv.cc.cc.lib - prisma.package - pkgs.nixfmt-rfc-style - yarn-v1 - yarn-berry - ]; - env = prisma.env; - }; - } - ) - // { - lib = { - inherit prisma-factory; - }; }; + }; } diff --git a/lib/fetcher.nix b/lib/fetcher.nix index f336111..985cf31 100644 --- a/lib/fetcher.nix +++ b/lib/fetcher.nix @@ -51,7 +51,8 @@ let zlib openssl stdenv.cc.cc.lib - ] ++ lib.optionals (!isDarwin) [ autoPatchelfHook ]; + ] + ++ lib.optionals (!isDarwin) [ autoPatchelfHook ]; phases = [ "installPhase" "postFixupHooks" diff --git a/lib/legacyFetcher.nix b/lib/legacyFetcher.nix index 8180cb4..4f48349 100644 --- a/lib/legacyFetcher.nix +++ b/lib/legacyFetcher.nix @@ -89,7 +89,8 @@ rec { zlib openssl stdenv.cc.cc.lib - ] ++ lib.optionals (!isDarwin) [ autoPatchelfHook ]; + ] + ++ lib.optionals (!isDarwin) [ autoPatchelfHook ]; phases = [ "buildPhase" "postFixupHooks" diff --git a/readme.md b/readme.md index 80e711b..8dc14ae 100644 --- a/readme.md +++ b/readme.md @@ -67,13 +67,13 @@ The [Legacy API](./legacy-api.md) (with fromNpmLock, fromYarnLock, etc.) is now Before contributing, please make sure that your code is formatted correctly by running ```sh -nix fmt +treefmt ``` All tests (including format check) can be run by ```sh -nix flake check +nix flake check ./dev ``` ## License