blob: 5cd80beeabff28c8651d951d3ca33f4a04f2120a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
{
description = "Port of Composer, the dependency manager for PHP, written in Rust";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
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";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
treefmt-nix = {
url = "github:numtide/treefmt-nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
composer,
flake-utils,
rust-overlay,
treefmt-nix,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlays.default ];
};
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
treefmt = treefmt-nix.lib.evalModule pkgs {
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
php
php.packages.composer
pkgs.just
# The following softwares are used for testing:
# VCSs
pkgs.git
# VCSs (optional)
# Neither Composer's test suite nor Shirabe's uses a real binary
# for these commands: all tests for them mock a process executor.
# They only slow the tests down.
# Please uncomment to run those code paths by hand.
# pkgs.fossil
# pkgs.mercurial
# pkgs.subversion
# Archivers
pkgs.bzip2
pkgs.gnutar
pkgs.gzip
pkgs.p7zip
pkgs.unzip
pkgs.xz
pkgs.zip
];
};
}
);
}
|