# System-manager module for Ubuntu systems
{ config, lib, pkgs, ... }:

let
	workshopPackages = import ./packages.nix { inherit pkgs; };
in
{
	config = {
		nixpkgs.hostPlatform = "x86_64-linux";

		environment.systemPackages = workshopPackages;

		# Create a script to configure perf permissions
		# (system-manager cannot set sysctl directly)
		environment.etc."perf-workshop-setup.sh" = {
			mode = "0755";
			text = ''
				#!/bin/sh
				# Run this script to enable perf for non-root users
				echo "Setting kernel.perf_event_paranoid=1..."
				sudo sysctl -w kernel.perf_event_paranoid=1

				# Make it persistent
				if ! grep -q "kernel.perf_event_paranoid" /etc/sysctl.conf 2>/dev/null; then
					echo "kernel.perf_event_paranoid=1" | sudo tee -a /etc/sysctl.conf
					echo "Added to /etc/sysctl.conf for persistence"
				fi

				echo "Done! You can now use perf as a regular user."
			'';
		};
	};
}
