From 7f987096aa88dfb07c2093591031267ea1eb00a0 Mon Sep 17 00:00:00 2001 From: Ben C Date: Mon, 5 Oct 2026 11:55:10 -0400 Subject: [PATCH] moodle-vm: init --- .gitignore | 3 ++ CONTRIBUTING.md | 16 ++++++++++ justfile | 5 +++ pkgs/moodle-vm.nix | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 pkgs/moodle-vm.nix diff --git a/.gitignore b/.gitignore index 9c2472b..5b6c029 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ target/ # ctags /tags + +# VM disk images +*.qcow2 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 890670d..3281dbf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,6 +15,22 @@ You can start a Nix devshell with `just devshell`. It's recommended you are in the devshell when working on the project, also most just recipes will expect binaries included in the devshell. +## Moodle LMS + +`just moodle` can be used to run a VM with Moodle inside it for testing. Note +you will need to let the `moodle-init` service run to setup Moodle before trying +to access it. You can login with `root`, `root` and then +`journalctl -f -u moodle-init` to watch progress. Moodle will be hosted on port +6767 and you can connect and login (username: `admin`, password: `testingpass`). + +To add BEDLAB as a tool, navigate to `Site Administration` -> `Plugins` -> +`Manage External Tools`. Get a registration link from `/lti/register-link` in +the BEDLAB instance (note this path is subject to change and will be behind auth +at some point). Copy the given link into the URL field in Moodle, then click +"LTI Advantage". The tool will ask to confirm and you should be good to go. You +then need to enable the tool in Moodle to use it (`Manage preconfigured tools` +-> `Pending` -> Approve BEDLAB). + ## Adding Pages 1. Make a Jinja template in `templates/`. 99.9% of the time you want it to diff --git a/justfile b/justfile index fffbda7..ecba0d9 100644 --- a/justfile +++ b/justfile @@ -28,6 +28,11 @@ devshell: dev: BEDROCK_TEST_ENV=$(nix build .?rev={{ REV }}#runner-test-env --no-link --print-out-paths) cargo run --bin br-web -- config.dev.toml +# run a Moodle testing VM +[no-cd] +moodle: + nix run .?rev={{ REV }}#moodle-vm + # simple nix repl [no-cd] repl: diff --git a/pkgs/moodle-vm.nix b/pkgs/moodle-vm.nix new file mode 100644 index 0000000..7c32a73 --- /dev/null +++ b/pkgs/moodle-vm.nix @@ -0,0 +1,80 @@ +{ nixos }: +(nixos ( + { + pkgs, + lib, + config, + ... + }: + { + networking.hostName = "moodle"; + system.stateVersion = "26.05"; + + virtualisation.vmVariant.virtualisation = { + memorySize = 3072; + cores = 2; + diskSize = 8192; + graphics = false; + forwardPorts = [ + { + from = "host"; + host.port = 6767; + guest.port = 80; + } + ]; + }; + + services.postgresql = { + enable = true; + package = pkgs.postgresql_16; + }; + + # Temp hack fix for https://github.com/NixOS/nixpkgs/issues/527266 + # There's a PR open to fix it so if it gets merged we can remove the lib.mkOverride + services.httpd.virtualHosts.localhost = + let + fpm = config.services.phpfpm.pools.moodle; + documentRoot = "${config.services.moodle.package}/share/moodle/public"; + in + { + documentRoot = lib.mkOverride 1 documentRoot; + # Line #1 is important and not part of the nixpkgs issue! + # It makes sure that the Authotization header gets forwarded properly to Moodle. + # This is required for LTI dynamic registration. + extraConfig = lib.mkOverride 1 '' + SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 + + + + SetHandler "proxy:unix:${fpm.socket}|fcgi://localhost/" + + + Options -Indexes + DirectoryIndex index.php + + ''; + }; + + services.moodle = { + enable = true; + database = { + type = "pgsql"; + createLocally = true; + name = "moodle"; + user = "moodle"; + }; + virtualHost = { + hostName = "localhost"; + adminAddr = "fake@example.com"; + }; + initialPassword = "testingpass"; + extraConfig = '' + $CFG->wwwroot = 'http://localhost:6767'; + ''; + }; + + networking.firewall.allowedTCPPorts = [ 80 ]; + + users.users.root.password = "root"; + } +)).vm -- knotmirror 0.0.1