Skip to content

Nix and Nix‐shell

DeeKahy edited this page Dec 12, 2024 · 5 revisions

Complete Guide to Using nix-shell

Windows special instructions - Linux and macOS should skip this section.

If you don't have WSL2, or are unsure if you have WSL2, it is a good idea to follow this official Microsoft guide to set it up: https://learn.microsoft.com/en-us/windows/wsl/install

After that is done, you can run sudo apt install neofetch and then run neofetch to see if you have WSL2 installed and set up properly.

We are now assuming you have entered a WSL2 terminal. If you have WSL2 set up properly, you should now clone the moodle repository or your own fork of it inside a WSL folder. (this is because leaving it inside a Windows folder has serious performance issues.)

cd ~
gh repo clone AAU-P5-Moodle/moodle-1 # Or whatever your repo is called.
ls 
cd moodle-1 # or whatever your folder name is.

Installing Nix

To properly install nix, you need to go to this website, https://nixos.org/download/ and follow the instructions for your operating system. (Linux, macOS, or windows)

Understanding nix-shell Basics

  • How to use nix-shell Just go to the root of your moodle repository and run nix-shell and it will automatically set up the environment + the database for you. Then please run Create_Config to automatically create a working moodle config (please don't create one yourself). Then you can go to 127.0.0.1:8000 to view moodle and 127.0.0.1:8080 for adminer (a database administration tool)

Common commands

Create_Config - automatically creates a moodle config with all the needed extra features such as tests. Sniffit -runs code sniffer Fixit - normally run after sniffit to automatically fix all automatically fixable errors. Runit - to automatically run all unit tests. Beit - runs all the behat tests.

Troubleshooting

  • If you are having issues, make sure to read the FAQ below.

FAQ

General - Any command shown here should be run from within an active nix-shell environment.

  • what ports do I use? Database: 3306, Moodle: 8000, Adminer: 8080
  • How do I run PHPUnit tests? Run runit. This will set up and run PHPUnit tests for you. Be aware that the first run might take a while.
  • How do I quickly set up moodle after deleting config.php. Just run create_config. This will set up the config.php for you.
  • How do I run CodeSniffer? Run sniffit. This will run the CodeSniffer for you.
  • How do I run CodeSniffer so it automatically fixes errors for me? Make sure to run sniffit first, and then run fixit. This will run the CodeSniffer fixer for you. Keep in mind this can only fix some errors.
  • How do I reset the database? Exit nix-shell by writing exit, then delete the mariadb_data folder and run nix-shell again.
  • I can't open adminer (localhost:8080) what do I do? It is likely that you already have MariaDB running on this port, so you need to make sure it is disabled, and then re-run nix-shell
  • How do I use behat? Run beit. This will set up and run behat test for you. Be aware that the first run might take a while. Doesn't work on macOS
  • How do I use grunt? Make sure you have a working config.php file (make sure PHPUnit and CodeSniffer can properly run). Then you can run gruntit, This will install, configure, and run grunt on our project to minify the JavaScript files. gruntit is currently available only in the websocket-branch, but it can easily be added to the default.nix file in the main branch. To do so, add nodejs_20 to the pkgs.mkShell buildInputs. Add the following script to the shellHook:
gruntit(){
      CURRENT_PATH="$(pwd)"
      cd $MOODLE_ROOT
      npm install
      cd mod/livequiz
      npx grunt stylelint
      npx grunt js
      cd $CURRENT_PATH
}

Then gruntit can run as described above.

WSL2

  • My performance is bad, how do I fix it? Make sure you have WSL2 set up properly, and that you are running the moodle repository from within a WSL folder. (see windows special instructions above)

macOS

  • macOS cannot run beit as no browser is on nix store for mac

Contact DeeKahy on discord if you really cant figure it out. (please i dont want to be spammed)

Clone this wiki locally