Skip to content

Commit

Permalink
Merge pull request #175 from traP-jp/feat/#137-compile-run-command
Browse files Browse the repository at this point in the history
✨ languageSettings出力
  • Loading branch information
Kentaro1043 authored Dec 24, 2024
2 parents ca5eaf9 + c18919c commit 11c36b1
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 2 deletions.
2 changes: 1 addition & 1 deletion exec-container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM --platform=amd64 nixos/nix:2.25.2

# configの修正、ワークスペースの作成
RUN echo "filter-syscalls = false" >> /etc/nix/nix.conf \
RUN printf "filter-syscalls = false\nexperimental-features = nix-command flakes" >> /etc/nix/nix.conf \
&& mkdir /workspace
COPY . /workspace
WORKDIR /workspace
Expand Down
2 changes: 1 addition & 1 deletion exec-container/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -eux
touch result
docker build -t trao-nix .
docker volume create trao-nix_cache
docker run -v ./result:/result -v trao-nix_cache:/nix/store --platform=linux/amd64 trao-nix
docker run -v ./result:/result -v trao-nix_cache:/nix/store trao-nix
8 changes: 8 additions & 0 deletions exec-container/compilers/brainfuck/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
myClang = pkgs.clang;
in
pkgs.writeShellScriptBin "bfc" "PATH=${myClang}/bin:$PATH exec ${myBrainfuck}/bin/bfc $@"
// {
traojudge = {
name = "Brainfuck";
binName = "bfc";
compile = "${myBrainfuck} \"$SRC\"";
run = "exec \"$DIST\""; # TODO: bfcは出力ファイルを指定できなさそうなので、これは変えないといけない
};
}
10 changes: 10 additions & 0 deletions exec-container/compilers/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,14 @@ in {
haxe
raku
];
traojudge = [
#golang.traojudge
brainfuck.traojudge
#rust.traojudge
#koka.traojudge
#mercury.traojudge
#cobol.traojudge
#haxe.traojudge
#raku.traojudge
];
}
16 changes: 16 additions & 0 deletions exec-container/docker/languageSettings-in-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/root/.nix-profile/bin/bash

# コンテナビルド
if ! nix build --extra-experimental-features nix-command --extra-experimental-features flakes .#languageSettings
then
exit 1
fi

# /resultに書き込み権限を付与
chmod u+w /result

# ビルド結果をコピー
realpath /workspace/result | xargs -I {} cp {} /result

# 読み取り専用に戻す
chmod u-w /result
2 changes: 2 additions & 0 deletions exec-container/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@
self.packages.${system}.environment
];
};
languageSettings = import ./languageSettings.nix {inherit pkgs allpkgs;};
};

formatter = pkgs.alejandra;
});
}
18 changes: 18 additions & 0 deletions exec-container/interpreters/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,22 @@ in {
r
prolog
];
traojudge = [
python.python311.traojudge
python.python312.traojudge
python.python312-quantum.traojudge
#bash.traojudge
#sed.traojudge
#node.traojudge
#seed7.traojudge
#pwsh.traojudge
## sagemath.traojudge
#awk.traojudge
#whitespace.traojudge
#unison.traojudge
#zsh.traojudge
#lua.traojudge
#r.traojudge
#prolog.traojudge
];
}
11 changes: 11 additions & 0 deletions exec-container/interpreters/python/3.11/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@
]);
in
pkgs.writeShellScriptBin "python3.11" "exec ${myPython}/bin/python $@"
// {
traojudge = {
name = "Python3.11";
binName = "python3.11";
compile = "cp \"$SRC\" \"$DIST\"";
run = "exec ${myPython}/bin/python \"$DIST\"";
#libraries = [
# バージョンが指定されていないので書けない
#]
};
}
66 changes: 66 additions & 0 deletions exec-container/interpreters/python/3.12-quantum/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,69 @@
python-modified = pythonSet.mkVirtualEnv "hello-world-env" workspace.deps.default;
in
pkgs.writeShellScriptBin "python3.12-quantum" "exec ${python-modified}/bin/python $@"
// {
traojudge = {
name = "Python3.12-quantum";
binName = "python3.12-quantum";
compile = "cp \"$SRC\" \"$DIST\"";
run = "exec ${python-modified}/bin/python \"$DIST\"";
libraries = [
{
name = "qiskit";
version = "1.2.4";
}
{
name = "numpy";
version = "2.1.3";
}
{
name = "scipy";
version = "1.14.1";
}
{
name = "networkx";
version = "3.4.2";
}
{
name = "sympy";
version = "1.13.3";
}
{
name = "sortedcontainers";
version = "2.4.0";
}
{
name = "more-itertools";
version = "10.5.0";
}
{
name = "shapely";
version = "2.0.6";
}
{
name = "bitarray";
version = "3.0.0";
}
{
name = "pulp";
version = "2.9.0";
}
{
name = "mpmath";
version = "1.3.0";
}
{
name = "pandas";
version = "2.2.3";
}
{
name = "z3-solver";
version = "4.13.3.0";
}
{
name = "scikit-learn";
version = "1.5.2";
}
];
};
}
11 changes: 11 additions & 0 deletions exec-container/interpreters/python/3.12/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@
]);
in
pkgs.writeShellScriptBin "python3.12" "exec ${myPython}/bin/python $@"
// {
traojudge = {
name = "Python3.12";
binName = "python3.12";
compile = "cp \"$SRC\" \"$DIST\"";
run = "exec ${myPython}/bin/python \"$DIST\"";
#libraries = [
# バージョンが指定されていないので書けない
#]
};
}
34 changes: 34 additions & 0 deletions exec-container/languageSettings.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
pkgs,
allpkgs,
}: let
interpreters = import ./interpreters {inherit allpkgs;};
compilers = import ./compilers {inherit allpkgs;};

languagesArray = {
languages = interpreters.traojudge ++ compilers.traojudge;
};
jsonOutput = builtins.toJSON languagesArray;
jsonFile = pkgs.writeText "languages.json" jsonOutput;
in
pkgs.stdenv.mkDerivation {
name = "language-settings";
nativeBuildInputs = [pkgs.check-jsonschema];
srcs = [
jsonFile
./schema.json
];
unpackPhase = ''
for _src in $srcs; do
cp "$_src" $(stripHash "$_src")
done
'';
dontBuild = true;
doCheck = true;
checkPhase = ''
check-jsonschema --schemafile schema.json languages.json
'';
installPhase = ''
mv languages.json $out
'';
}
8 changes: 8 additions & 0 deletions exec-container/languageSettings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -eux

touch result
docker build -t trao-nix .
docker volume create trao-nix_cache
docker run -v ./result:/result -v trao-nix_cache:/nix/store trao-nix /workspace/docker/languageSettings-in-docker.sh

0 comments on commit 11c36b1

Please sign in to comment.