chore: add web server package
This commit is contained in:
43
flake.nix
43
flake.nix
@@ -105,6 +105,49 @@
|
||||
mv ./build/slopvivors "$out"/index.html
|
||||
'';
|
||||
};
|
||||
slopvivors_web = pkgs.buildGoModule {
|
||||
pname = "slopvivors-web";
|
||||
version = "0.1.0";
|
||||
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
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
|
Reference in New Issue
Block a user