Skip to content

Commit fe89247

Browse files
authored
Merge pull request #289 from MelbourneHighSchoolRobotics/nix
Nix builds for Linux
2 parents 11942df + f3e498e commit fe89247

21 files changed

Lines changed: 462 additions & 22 deletions

.github/workflows/nix_lint.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Nix linting
2+
3+
on:
4+
push:
5+
branches-ignore: gh-pages
6+
7+
jobs:
8+
check-nix-lint:
9+
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v1
14+
15+
- uses: cachix/install-nix-action@v13
16+
with:
17+
nix_path: nixpkgs=channel:nixos-21.05
18+
19+
- run: ./nix/lint.sh
20+
- run: ./nix/format.sh --check
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
name: Windows Executable Creation
22

3-
# Disabled as is broken
4-
on: []
3+
on:
4+
push:
5+
branches-ignore: gh-pages
56

67
jobs:
78
create-exe:
89

9-
runs-on: windows-latest
10+
runs-on: ubuntu-latest
1011

1112
steps:
1213
- uses: actions/checkout@v1
13-
# Standard drop-in approach that should work for most people.
1414

15-
- name: Set up Python
16-
uses: actions/setup-python@v2
15+
- uses: cachix/install-nix-action@v13
1716
with:
18-
python-version: 3.9
17+
install_url: https://nixos-nix-install-tests.cachix.org/serve/i6laym9jw3wg9mw6ncyrk6gjx4l34vvx/install
18+
install_options: '--tarball-url-prefix https://nixos-nix-install-tests.cachix.org/serve'
19+
extra_nix_config: |
20+
experimental-features = nix-command flakes
21+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
22+
- uses: cachix/cachix-action@v10
23+
with:
24+
name: melbournehighschoolrobotics
25+
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
1926

20-
- name: Install dependencies
21-
run: |
22-
python -m pip install --upgrade pip
23-
pip install -r requirements.txt
24-
pip install -r requirements-dev.txt
27+
- run: nix build --print-build-logs ".#windows"
28+
- run: nix flake check
2529

26-
- name: Build with pyinstaller
27-
run: |
28-
python -m build_exe
29-
# Create an artifact of the html output.
3030
- uses: actions/upload-artifact@v1
3131
with:
3232
name: windows_package
33-
path: dist/ev3sim
33+
path: result/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ share/python-wheels/
2525
.installed.cfg
2626
*.egg
2727
MANIFEST
28+
result
2829

2930
# PyInstaller
3031
# Usually these files are written by a python script from a template

build_exe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
if os.path.exists("dist/ev3sim/user_config.yaml"):
2121
os.remove("dist/ev3sim/user_config.yaml")
2222

23-
process = Popen("makensis config.nsi")
23+
process = Popen(["makensis", "config.nsi"])
2424
process.wait()
2525
shutil.move("installer.exe", "installer-32bit.exe")
2626

@@ -35,6 +35,6 @@
3535
if os.path.exists("dist/ev3sim/user_config.yaml"):
3636
os.remove("dist/ev3sim/user_config.yaml")
3737

38-
process = Popen("makensis config.nsi")
38+
process = Popen(["makensis", "config.nsi"])
3939
process.wait()
4040
shutil.move("installer.exe", "installer-64bit.exe")

config.nsi

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ File /nonfatal /a /r "dist\"
8383
WriteRegStr HKCU "Software\EV3Sim" "" $InstDir
8484

8585
;Run pip install process. pythonw seems to not finish correctly, and so ev3sim doesn't get installed.
86-
;To use test.pypi: '"$InstDir\python_embed\python.exe" -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple ev3sim==2.1.8.post1'
87-
ExecDos::exec '"$InstDir\python_embed\python.exe" -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org ev3sim' "" "$InstDir\pip.log"
86+
ExecDos::exec '"$InstDir\python_embed\python.exe" -m pip install -f "$InstDir\python_embed\wheels" --no-index ev3sim' "" "$InstDir\pip.log"
8887
Pop $0
8988
StrCmp "0" $0 fine
9089

docs/contributing.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,44 @@ Pull requests are linted with `black`_. To run black locally to fix any formatti
3131
black --config pyproject.toml .
3232
3333
.. _black: https://github.com/psf/black
34+
35+
Building with Nix
36+
-----------------
37+
38+
The `Nix <https://nixos.org/>`_ package manager can be used to create reproducible builds on Linux and Mac.
39+
40+
Setup
41+
^^^^^
42+
43+
First `install Nix <https://nixos.org/download.html>`_ with experimental `Flakes <https://nixos.wiki/wiki/Flakes#Non-NixOS>`_ support.
44+
45+
.. code-block:: bash
46+
47+
curl -L https://nixos.org/nix/install | sh
48+
. /home/$USER/.nix-profile/etc/profile.d/nix.sh
49+
50+
nix-env -iA nixpkgs.nixUnstable
51+
mkdir -p ~/.config/nix
52+
echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf
53+
54+
Then set up the binary cache for faster builds.
55+
56+
.. code-block:: bash
57+
58+
nix-env -iA cachix -f https://cachix.org/api/v1/install
59+
cachix use melbournehighschoolrobotics
60+
61+
Release
62+
^^^^^^^
63+
64+
To build installers for Windows:
65+
66+
.. code-block:: bash
67+
68+
nix build ".#windows"
69+
70+
To build for Linux:
71+
72+
.. code-block:: bash
73+
74+
nix build ".#linux"

ev3sim/search_locations.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
preset_locations = lambda: ["workspace/presets/", "workspace", "package/presets/"]
2-
config_locations = lambda: ["workspace", "package"]
32
device_locations = lambda: ["workspace/devices/", "package/devices/"]
43
theme_locations = lambda: ["workspace/assets/", "workspace", "package/assets"]
54
asset_locations = lambda: ["workspace/assets/", "workspace", "package/assets/"]
65

76

7+
def config_locations():
8+
import os
9+
import platform
10+
from pathlib import Path
11+
12+
if platform.system() == "Linux":
13+
home_dir = os.path.expanduser("~")
14+
xdg_config_dir = os.environ.get("XDG_CONFIG_HOME") or os.path.join(home_dir, ".config")
15+
config_dir = os.path.join(xdg_config_dir, "ev3sim")
16+
# Ensure config dir exists
17+
Path(config_dir).mkdir(parents=True, exist_ok=True)
18+
return ["workspace", "local|" + config_dir]
19+
20+
return ["workspace", "package"]
21+
22+
823
def code_locations(bot_path):
924
from ev3sim.file_helper import find_abs_directory
1025

flake.lock

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
description = "A simulator for soccer robots programmed with ev3dev.";
3+
4+
inputs.nixpkgs.url = "github:nixos/nixpkgs/21.05";
5+
# On unstable to use some new python packages. Eventually will be merged into Nix 21.11
6+
inputs.unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
7+
inputs.flake-utils.url = "github:numtide/flake-utils";
8+
inputs.mindpile.url = "github:MelbourneHighSchoolRobotics/mindpile";
9+
inputs.mindpile.inputs.nixpkgs.follows = "nixpkgs";
10+
inputs.mindpile.inputs.flake-utils.follows = "flake-utils";
11+
12+
outputs = { nixpkgs, unstable, flake-utils, mindpile, ... }:
13+
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
14+
let
15+
pkgs = nixpkgs.legacyPackages.${system};
16+
unstablePkgs = unstable.legacyPackages.${system};
17+
in rec {
18+
packages = {
19+
linux = pkgs.callPackage ./nix/linux.nix {
20+
inherit (unstablePkgs.python39Packages) ev3dev2 opensimplex pymunk pygame pygame-gui;
21+
mindpile = mindpile.legacyPackages.${system}.mindpile;
22+
};
23+
24+
windows = pkgs.callPackage ./nix/windows-installer.nix { };
25+
};
26+
defaultPackage = packages.linux;
27+
});
28+
}

nix/ev3dev2-wheel.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# HACK! Build an ev3dev2 wheel natively as it doesn't build under Wine for some reason, and isn't on PyPi
2+
{ pkgs, fetchurl, ... }:
3+
let
4+
ev3dev2 = fetchurl {
5+
url =
6+
"https://files.pythonhosted.org/packages/8a/8c/2ddffc70572989acb5d2f60e5e1d7e93f6daf9b05200ac0e80d030e98950/python-ev3dev2-2.1.0.post1.tar.gz";
7+
sha256 = "0j89fgcmr8vx9maifr2jrihxjci0c3mgmmq0yg42mbmnx2q6kz8c";
8+
};
9+
python = pkgs.python39.withPackages (p: with p; [ pip setuptools wheel ]);
10+
in pkgs.runCommandNoCC "ev3dev2-wheel" { } ''
11+
mkdir $out
12+
${python}/bin/python -m pip wheel -w $out --no-deps --no-index ${ev3dev2}
13+
''

0 commit comments

Comments
 (0)