Skip to content

Instantly share code, notes, and snippets.

@Aeva
Created May 13, 2024 01:55
Show Gist options
  • Save Aeva/cd254dea1e68c63ea736aa64695085fd to your computer and use it in GitHub Desktop.
Save Aeva/cd254dea1e68c63ea736aa64695085fd to your computer and use it in GitHub Desktop.
distrobox nix-shell and notes on setting up monogame for development on nixos
{ pkgs ? import <nixpkgs> {} }:
let
# To use this shell.nix on NixOS your user needs to be configured as such:
# users.extraUsers.adisbladis = {
# subUidRanges = [{ startUid = 100000; count = 65536; }];
# subGidRanges = [{ startGid = 100000; count = 65536; }];
# };
# Provides a script that copies required files to ~/
podmanSetupScript = let
registriesConf = pkgs.writeText "registries.conf" ''
[registries.search]
registries = ['docker.io']
[registries.block]
registries = []
'';
in pkgs.writeScript "podman-setup" ''
#!${pkgs.runtimeShell}
# Dont overwrite customised configuration
if ! test -f ~/.config/containers/policy.json; then
install -Dm555 ${pkgs.skopeo.src}/default-policy.json ~/.config/containers/policy.json
fi
if ! test -f ~/.config/containers/registries.conf; then
install -Dm555 ${registriesConf} ~/.config/containers/registries.conf
fi
'';
# Provides a fake "docker" binary mapping to podman
dockerCompat = pkgs.runCommandNoCC "docker-podman-compat" {} ''
mkdir -p $out/bin
ln -s ${pkgs.podman}/bin/podman $out/bin/docker
'';
in pkgs.mkShell {
buildInputs = [
dockerCompat
pkgs.podman # Docker compat
pkgs.runc # Container runtime
pkgs.conmon # Container runtime monitor
pkgs.skopeo # Interact with container registry
pkgs.slirp4netns # User-mode networking for unprivileged namespaces
pkgs.fuse-overlayfs # CoW for images, much faster than default vfs
pkgs.distrobox
];
shellHook = ''
# Install required configuration
${podmanSetupScript}
'';
# To setup a new fedora container for monogame development
# > distrobox create -i fedora:latest -n monogame
# Once in a new fedora container, run this to get everything set up:
# > sudo dnf install dotnet-sdk-6.0 glx-utils mesa-demos bash-color-prompt
# > dotnet new --install MonoGame.Templates.CSharp
# Interestingly if I omit mese-demos, monogame applications will fail to
# load as I'm seeing in nix. That doesn't really narrow it down though,
# since mesa-demos pulls in a LOT.
# The `bash-color-prompt` package is not necessary, but nice to have.
}
@Aeva
Copy link
Author

Aeva commented May 13, 2024

The first part of this is code that I copied from I don't remember where and it gets distrobox setup on NixOS. The comment at the end discusses what to install on the guest OS to get you started with making stuff with MonoGame.

This is my work around for now to bypass the multitude of problems that I've ran into trying to get MonoGame working with NixOS the normal way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment