From 6eb992efdd68d80bc62bc7fc0562d8a2e6558096 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Mon, 6 Sep 2021 15:32:19 +0200 Subject: add nix build system and NixOS module --- default.nix | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 default.nix (limited to 'default.nix') diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..bc7afc9 --- /dev/null +++ b/default.nix @@ -0,0 +1,70 @@ + +{pkgs ? import (import ./nix/sources.nix).nixpkgs {}}: + +let + defaultcards = pkgs.copyPathToStore ./cards.yaml; + drvs = with pkgs; rec { + + # server derivation generated using cabal2nix + uplcg-server = + { mkDerivation, aeson, async, base, blaze-html, bytestring + , elm-bridge, fast-logger, hashable, http-types, lens, lib, mtl + , process, random, scotty, stm, template-haskell, text, time + , unordered-containers, uuid, vector, vector-algorithms + , vector-instances, vector-shuffling, wai, wai-extra + , wai-websockets, warp, websockets, yaml }: + + mkDerivation { + pname = "uplcg"; + version = "0.1.0"; + src = ./server; + isLibrary = true; + isExecutable = true; + libraryHaskellDepends = [ + aeson async base blaze-html bytestring elm-bridge fast-logger + hashable http-types lens mtl process random scotty stm + template-haskell text time unordered-containers uuid vector + vector-algorithms vector-instances vector-shuffling wai wai-extra + wai-websockets warp websockets yaml + ]; + executableHaskellDepends = [ base ]; + description = "Untitled PL Card Game"; + license = lib.licenses.bsd3; + + # TODO: get the actual version hash in here + patchPhase = '' + rm lib/Uplcg/Version.hs + echo "module Uplcg.Version (version) where" > lib/Uplcg/Version.hs + echo "version :: String" >> lib/Uplcg/Version.hs + echo "version = \"nixpkgs-uplcg\"" >> lib/Uplcg/Version.hs + ''; + }; + + uplcg-client = { cards ? defaultcards, server}: + stdenv.mkDerivation { + name = "uplcg-client"; + src = ./client; + + buildInputs = [ elmPackages.elm ]; + + buildPhase = elmPackages.fetchElmDeps { + elmPackages = import ./client/elm-srcs.nix; + elmVersion = "0.19.1"; + registryDat = ./client/registry.dat; + }; + + installPhase = '' + mkdir -p $out/assets + cp -r $src/* . + ${server}/bin/uplcg-generate-elm-types > src/Messages.elm + elm make src/Client.elm --optimize --output client.js + cp client.js $out/assets + cp style.css $out/assets + cp ${cards} $out/assets/cards.yaml + ''; + }; + }; +in with pkgs.lib; rec { + client = callPackageWith { inherit server; } drvs.uplcg-client {}; + server = pkgs.haskellPackages.callPackage drvs.uplcg-server {}; +} -- cgit v1.2.3