diff --git a/flake.lock b/flake.lock index c010959..394c805 100644 --- a/flake.lock +++ b/flake.lock @@ -20,16 +20,15 @@ }, "nixpkgs": { "locked": { - "lastModified": 1741851582, - "narHash": "sha256-cPfs8qMccim2RBgtKGF+x9IBCduRvd/N5F4nYpU0TVE=", + "lastModified": 1769385949, + "narHash": "sha256-SRQaiH9ckO3I/4kGHJSepJl/R0RqdyycdBnnlQ5saKY=", "owner": "nixos", "repo": "nixpkgs", - "rev": "6607cf789e541e7873d40d3a8f7815ea92204f32", + "rev": "b3ac5a8a8ca2e8a57b387b1dda5e790132afdd8c", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixos-unstable", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index 53d25d9..3313a44 100644 --- a/flake.nix +++ b/flake.nix @@ -1,28 +1,46 @@ { description = "A JS devtool orchestrator"; inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + nixpkgs.url = "github:nixos/nixpkgs"; flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.eachDefaultSystem (system: - let - manifest = (pkgs.lib.importTOML ./crates/depot/Cargo.toml).package; - pkgs = import nixpkgs { inherit system; }; - depot-js = pkgs.rustPlatform.buildRustPackage rec { - pname = manifest.name; - version = manifest.version; - cargoLock.lockFile = ./Cargo.lock; - src = pkgs.lib.cleanSource ./.; - nativeBuildInputs = [ pkgs.git ]; - # NOTE: depot's tests have a lot of external dependencies: node, biome, ... - # We'll ignore them for now and figure it out later ;) - doCheck = false; - }; - in { - packages = { - default = depot-js; - }; - }); + outputs = + { + self, + nixpkgs, + flake-utils, + }: + let + depotOverlay = final: prev: { + depot = final.callPackage ./nix/package.nix { + cleanSource = prev.lib.cleanSource; + }; + + mkDepotPackage = final.callPackage ./nix/mk-depot-package.nix { + depot = final.depot; + }; + }; + in + { + overlays.default = depotOverlay; + } + // flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ depotOverlay ]; + }; + in + { + packages = { + default = pkgs.depot; + }; + + devShells.default = pkgs.mkShell { + inputsFrom = [ pkgs.depot ]; + }; + } + ); } diff --git a/nix/mk-depot-package.nix b/nix/mk-depot-package.nix new file mode 100644 index 0000000..7d36481 --- /dev/null +++ b/nix/mk-depot-package.nix @@ -0,0 +1,61 @@ +{ + lib, + stdenv, + cacert, + nodejs_22, + pnpm_9, + depot, +}: + +{ + pname, + version, + src, + pnpmHash, # The checksum for pnpm-lock.yaml + distDir ? "dist", # Where the build output lands (relative to root) + extraNativeBuildInputs ? [ ], + ... +}@args: + +stdenv.mkDerivation ( + finalAttrs: + (builtins.removeAttrs args [ + "pnpmHash" + "distDir" + "extraNativeBuildInputs" + ]) + // { + nativeBuildInputs = [ + cacert + pnpm_9 + nodejs_22 + depot + ] + ++ extraNativeBuildInputs; + + pnpmDeps = pnpm_9.fetchDeps { + inherit (finalAttrs) pname version src; + fetcherVersion = 2; + hash = pnpmHash; + }; + + buildPhase = '' + set -euo pipefail + + # 1. Setup PNPM Store + export NPM_CONFIG_OFFLINE=true + export PNPM_WRITABLE_STORE=$(mktemp -d) + cp -LR ${finalAttrs.pnpmDeps}/* $PNPM_WRITABLE_STORE/ || true + chmod -R +w $PNPM_WRITABLE_STORE + export npm_config_store_dir=$PNPM_WRITABLE_STORE + + # 2. Run Depot Build + depot b --release + ''; + + installPhase = '' + mkdir -p $out + cp -r ${distDir}/* $out/ + ''; + } +) diff --git a/nix/package.nix b/nix/package.nix new file mode 100644 index 0000000..1b61669 --- /dev/null +++ b/nix/package.nix @@ -0,0 +1,18 @@ +{ + lib, + rustPlatform, + git, + cleanSource, +}: + +let + manifest = (lib.importTOML ../crates/depot/Cargo.toml).package; +in +rustPlatform.buildRustPackage { + pname = manifest.name; + version = manifest.version; + cargoLock.lockFile = ../Cargo.lock; + src = cleanSource ../.; + nativeBuildInputs = [ git ]; + doCheck = false; +}