Help needed with a systemd service

Hi, I’m looking for a solution for a couple of days now.

I maybe too new to this topic, but I did not find a solution here yet.

I want to set up an openvscode-server as a systemd service in nixos, to provide a c/cpp project to students in a browser. But with the default method some environment variables are not set inside the running server and so my cmake of the project breaks at criterion ( I want to expose with this codeserver is not building.

I’ve built a nix file which provides a nix-shell in which, when started properly, the openvscode-server runs and all environment variables are set correctly.

Is there somehow a straight forward way to convert this into a systemd service?

Cheers Robert

{ pkgs ? import <nixpkgs> {} }:

  download_plugins = [
  id_plugins = [
  vsix_files = pkgs.lib.lists.forEach download_plugins (x :  pkgs.fetchurl x );
  install_plugs = pkgs.writeShellScript "" ''
    for zvsix in ${toString vsix_files}; do
      echo installing ''${zvsic}
      zcat -d ''${zvsix} > plug.vsix
      openvscode-server --install-extension plug.vsix
      rm plug.vsix
    for extid in ${toString id_plugins}; do
      echo installing ''${extid}
      openvscode-server --install-extension ''${extid}
  start_server = pkgs.writeShellScript "" ''
    ${install_plugs} &
    openvscode-server --host --without-connection-token

pkgs.mkShell {
  packages = with pkgs; [ pstree coreutils busybox bashInteractive cmake gdb gcc gnumake git openvscode-server ];
  shellHook = ''
    echo run ${start_server}