From dfd9e72b1786597db643d50c7a55d1fcbadf7802 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 30 Aug 2026 16:24:31 +0900 Subject: build(nix): add a package output producing the binary Co-Authored-By: Claude Opus 5 --- flake.nix | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 100 insertions(+), 2 deletions(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index 5b51672e..5cd80bee 100644 --- a/flake.nix +++ b/flake.nix @@ -6,6 +6,11 @@ systems.url = "github:nix-systems/default"; + composer = { + url = "github:composer/composer/2.9.7"; + flake = false; + }; + flake-utils = { url = "github:numtide/flake-utils"; inputs.systems.follows = "systems"; @@ -24,7 +29,9 @@ outputs = { + self, nixpkgs, + composer, flake-utils, rust-overlay, treefmt-nix, @@ -42,15 +49,106 @@ imports = [ ./treefmt.nix ]; programs.rustfmt.package = rustToolchain; }; + + php = pkgs.php85; + + composerVersion = + let + versionLines = builtins.filter (match: match != null) ( + map (line: builtins.match " *public const VERSION = '(.*)';" line) ( + pkgs.lib.splitString "\n" (builtins.readFile "${composer}/src/Composer/Composer.php") + ) + ); + in + builtins.head (builtins.head versionLines); + + composerRuntime = pkgs.stdenvNoCC.mkDerivation { + pname = "composer-runtime"; + version = composerVersion; + src = composer; + nativeBuildInputs = [ + php + php.packages.composer + ]; + dontPatchShebangs = true; + buildPhase = '' + runHook preBuild + export COMPOSER_HOME="$TMPDIR/composer-home" + export COMPOSER_CACHE_DIR="$TMPDIR/composer-cache" + export COMPOSER_ROOT_VERSION="${composerVersion}" + composer install --no-dev --no-interaction --no-progress + runHook postBuild + ''; + installPhase = '' + runHook preInstall + cp -r . "$out" + runHook postInstall + ''; + + outputHashMode = "recursive"; + outputHashAlgo = "sha256"; + outputHash = "sha256-owdTo9YBaQv3a3FnUubBfI0gjca5XEJ84/PukcukPfc="; + }; + + commitTime = self.lastModified; + commitDate = self.lastModifiedDate; + + rustPlatform = pkgs.makeRustPlatform { + cargo = rustToolchain; + rustc = rustToolchain; + }; + + shirabe = rustPlatform.buildRustPackage { + pname = "shirabe"; + version = (builtins.fromTOML (builtins.readFile ./Cargo.toml)).workspace.package.version; + + src = pkgs.lib.fileset.toSource { + root = ./.; + fileset = pkgs.lib.fileset.unions [ + ./Cargo.toml + ./Cargo.lock + ./crates + ]; + }; + cargoLock.lockFile = ./Cargo.lock; + + postPatch = '' + cp -r ${composerRuntime} composer + chmod -R u+w composer + ''; + + env = { + SHIRABE_RELEASE_DATE = + let + field = start: builtins.substring start 2 commitDate; + in + "${builtins.substring 0 4 commitDate}-${field 4}-${field 6} ${field 8}:${field 10}:${field 12}"; + SHIRABE_DEV_WARNING_TIME = toString (commitTime + 60 * 86400); + }; + + doCheck = false; + + meta = { + description = "Rust port of Composer, the dependency manager for PHP"; + homepage = "https://github.com/nsfisis/php-shirabe"; + license = pkgs.lib.licenses.mit; + mainProgram = "shirabe"; + }; + }; in { formatter = treefmt.config.build.wrapper; + packages = { + inherit shirabe; + default = shirabe; + }; + devShells.default = pkgs.mkShell { packages = [ rustToolchain - pkgs.php85 - pkgs.php85Packages.composer + php + php.packages.composer pkgs.just # The following softwares are used for testing: -- cgit v1.3.1-4-g156e