Skip to content

Commit 16e4f08

Browse files
authored
Merge pull request #441 from Brikaa/nix-development
Use nodemon and Docker volumes for development
2 parents 7596d6f + 50978c4 commit 16e4f08

6 files changed

Lines changed: 801 additions & 92 deletions

File tree

Dockerfile.withset

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# This "FROM" image is previously emitted by nix
22
FROM ghcr.io/engineer-man/piston:base-latest
33

4-
ENV PISTON_FLAKE_PATH=/piston/packages
5-
COPY runtimes/ /piston/packages/runtimes
6-
COPY flake.nix flake.lock /piston/packages/
4+
ENV PISTON_FLAKE_PATH=/piston/src
5+
COPY runtimes/ /piston/src/runtimes
6+
COPY flake.nix flake.lock /piston/src/
77

88

99
ARG RUNTIMESET=all

api/default.nix

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{pkgs, nosocket, ...}:
1+
{pkgs, nosocket, isDev, ...}:
22
with pkgs; rec {
33
package = mkYarnPackage {
44
name = "piston";
@@ -25,36 +25,54 @@ with pkgs; rec {
2525
};
2626
};
2727
};
28+
29+
basePackages = with pkgs; [
30+
package
31+
nosocket
32+
bash
33+
nixFlakes
34+
coreutils-full
35+
cacert.out
36+
git
37+
gnutar
38+
gzip
39+
gnugrep
40+
rename
41+
util-linux
42+
];
43+
devPackages = with pkgs; [
44+
nodejs-16_x
45+
yarn
46+
python3
47+
gcc
48+
gnumake
49+
gnused
50+
];
51+
52+
baseCommands = ''
53+
mkdir -p piston/{jobs,runtimes} etc/nix {,var/}tmp run/lock
54+
echo -e "experimental-features = nix-command flakes" >> etc/nix/nix.conf
55+
echo "nixbld:x:30000:nixbld1,nixbld10,nixbld11,nixbld12,nixbld13,nixbld14,nixbld15,nixbld16,nixbld17,nixbld18,nixbld19,nixbld2,nixbld20,nixbld21,nixbld22,nixbld23,nixbld24,nixbld25,nixbld26,nixbld27,nixbld28,nixbld29,nixbld3,nixbld30,nixbld31,nixbld32,nixbld4,nixbld5,nixbld6,nixbld7,nixbld8,nixbld9" >> etc/group
56+
for i in $(seq 1 32)
57+
do
58+
echo "nixbld$i:x:$(( $i + 30000 )):30000:Nix build user $i:/var/empty:/run/current-system/sw/bin/nologin" >> etc/passwd
59+
done
60+
61+
chmod 1777 {,var/}tmp/
62+
'';
63+
devCommands = ''
64+
mkdir -p usr/bin
65+
ln -s /bin/env usr/bin/env
66+
chmod -R 1777 usr
67+
'';
68+
2869
container = pkgs.dockerTools.buildLayeredImageWithNixDb {
29-
name = "piston";
70+
name = if isDev then "piston" else "ghcr.io/engineer-man/piston";
3071
tag = "base-latest";
3172

32-
contents = with pkgs; [
33-
package
34-
nosocket
35-
bash
36-
nixFlakes
37-
coreutils-full
38-
cacert.out
39-
git
40-
gnutar
41-
gzip
42-
gnugrep
43-
rename
44-
util-linux
45-
];
46-
47-
extraCommands = ''
48-
mkdir -p piston/{jobs,runtimes} etc/nix {,var/}tmp run/lock
49-
echo -e "experimental-features = nix-command flakes" >> etc/nix/nix.conf
50-
echo "nixbld:x:30000:nixbld1,nixbld10,nixbld11,nixbld12,nixbld13,nixbld14,nixbld15,nixbld16,nixbld17,nixbld18,nixbld19,nixbld2,nixbld20,nixbld21,nixbld22,nixbld23,nixbld24,nixbld25,nixbld26,nixbld27,nixbld28,nixbld29,nixbld3,nixbld30,nixbld31,nixbld32,nixbld4,nixbld5,nixbld6,nixbld7,nixbld8,nixbld9" >> etc/group
51-
for i in $(seq 1 32)
52-
do
53-
echo "nixbld$i:x:$(( $i + 30000 )):30000:Nix build user $i:/var/empty:/run/current-system/sw/bin/nologin" >> etc/passwd
54-
done
73+
contents = if isDev then basePackages ++ devPackages else basePackages;
5574

56-
chmod 1777 {,var/}tmp/
57-
'';
75+
extraCommands = if isDev then baseCommands + devCommands else baseCommands;
5876

5977
config = {
6078
Cmd = ["${package}/bin/pistond"];
@@ -86,4 +104,4 @@ with pkgs; rec {
86104
};
87105
};
88106
};
89-
}
107+
}

api/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@
88
"express": "^4.17.1",
99
"express-ws": "^5.0.2",
1010
"logplease": "^1.2.15",
11+
"nocamel": "git://github.com/HexF/nocamel.git#patch-1",
1112
"node-fetch": "^2.6.1",
1213
"uuid": "^8.3.2",
13-
"nocamel": "git://github.com/HexF/nocamel.git#patch-1",
1414
"waitpid": "git://github.com/HexF/node-waitpid.git"
1515
},
1616
"license": "MIT",
1717
"scripts": {
18+
"dev": "nodemon .",
1819
"lint": "prettier . --write",
1920
"prepack": "yarn2nix > yarn.nix"
2021
},
2122
"devDependencies": {
2223
"node2nix": "^1.6.0",
24+
"nodemon": "^2.0.15",
2325
"prettier": "2.2.1"
2426
},
2527
"bin": {

0 commit comments

Comments
 (0)