Files
slopvivors/flake.nix

184 lines
5.0 KiB
Nix

{
description = "Survivor Slop game";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs =
{ self, nixpkgs }:
let
allSystems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems =
f:
nixpkgs.lib.genAttrs allSystems (
system:
f {
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
}
);
in
{
devShells = forAllSystems (
{ pkgs }:
{
default = pkgs.mkShell {
packages = with pkgs; [
aseprite
gdtoolkit_4
gimp
godot
krita
pixelorama
skopeo
];
shellHook = ''
alias slop-format='find . -name "*.gd" | xargs gdformat'
alias slop-push='nix build .#\slopvivors_docker && skopeo copy docker-archive:result docker://git.t-juice.club/torjus/slopvivors:latest'
'';
};
}
);
packages = forAllSystems (
{ pkgs }:
let
project_file = builtins.readFile ./project.godot;
version = builtins.head (builtins.match ".*version=\"([0-9.]+)\".*" project_file);
in
{
slopvivors = pkgs.stdenv.mkDerivation {
pname = "slopvivors";
version = version;
src = ./.;
strictDeps = true;
nativeBuildInputs = with pkgs; [
godot
];
buildPhase = ''
runHook preBuild
export HOME=$(mktemp -d)
mkdir -p $HOME/.local/share/godot/
ln -s ${pkgs.godot.export-template}/share/godot/export_templates "$HOME/.local/share/godot/"
mkdir -p build
godot --headless --export-release Linux ./build/slopvivors
runHook postBuild
'';
installPhase = ''
find .
install -D -m 755 -t $out/libexec ./build/slopvivors
install -D -m 644 -t $out/libexec ./build/slopvivors.pck
install -d -m 755 $out/bin
ln -s $out/libexec/slopvivors $out/bin/slopvivors
'';
};
slopvivors_web_files = pkgs.stdenv.mkDerivation {
pname = "slopvivors-web-files";
version = version;
src = ./.;
strictDeps = true;
nativeBuildInputs = with pkgs; [
godot
godot-export-templates-bin
];
buildPhase = ''
runHook preBuild
export HOME=$(mktemp -d)
mkdir -p $HOME/.local/share/godot/
ln -s ${pkgs.godot-export-templates-bin}/share/godot/export_templates "$HOME/.local/share/godot/"
mkdir -p build
godot --headless --export-release Web ./build/slopvivors
runHook postBuild
'';
installPhase = ''
mkdir -p "$out"
cp ./build/* "$out"
mv ./build/slopvivors "$out"/index.html
'';
};
slopvivors_web = pkgs.buildGoModule {
pname = "slopvivors-web";
version = version;
vendorHash = null;
src = self.packages.${pkgs.system}.slopvivors_web_files;
nativeBuildInputs = with pkgs; [
go
];
prePatch = ''
mkdir -p slopvivors_web_files
cp "${self.packages.${pkgs.system}.slopvivors_web_files}"/* slopvivors_web_files
cat > main.go <<EOF
package main
import (
"embed"
"fmt"
"net/http"
"io/fs"
)
//go:embed slopvivors_web_files/*
var webFiles embed.FS
func main() {
rootDir, err := fs.Sub(webFiles, "slopvivors_web_files")
if err != nil {
panic(err)
}
http.Handle("/", http.FileServer(http.FS(rootDir)))
fmt.Printf("Serving on :8080\n")
http.ListenAndServe(":8080", nil)
}
EOF
'';
postPatch = ''
go mod init slopvivors-web
'';
};
slopvivors_docker = pkgs.dockerTools.buildLayeredImage {
name = "slopvivors-docker";
tag = version;
created = "now";
contents = [
pkgs.busybox
pkgs.caddy
self.packages.${pkgs.system}.slopvivors_web_files
];
config = {
Cmd = [
"caddy"
"file-server"
"-a"
"--listen"
":8080"
];
WorkingDir = "${self.packages.${pkgs.system}.slopvivors_web_files}/";
};
};
}
);
};
}