diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..21282b0 --- /dev/null +++ b/.envrc @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +use flake \ No newline at end of file diff --git a/.gitignore b/.gitignore index cce9137..73b0670 100644 --- a/.gitignore +++ b/.gitignore @@ -26,5 +26,6 @@ cabal.project.local~ # ignore vscodium's local config .vscode/ -# ignore nix result symlinks -result* \ No newline at end of file +# ignore nix build system +result* +.direnv \ No newline at end of file diff --git a/Graphics/Engine.hs b/Graphics/Engine.hs index 5416a90..3ddab38 100644 --- a/Graphics/Engine.hs +++ b/Graphics/Engine.hs @@ -44,15 +44,15 @@ processEvent = event noEvent $ \case EventMotion {} -> noEvent EventResize size -> Event $ Resize size -run :: forall f. DisplayableSpace f => f Bool -> SF InputEvent Picture -run st = +run :: DisplayableSpace f => (Int, Int) -> f Bool -> SF InputEvent Picture +run size st = let initSpace = gol' standardRule st in proc inp -> do let cmdev = processEvent inp playing <- accumHoldBy (const . not) True -< filterE isPlayPause cmdev time <- accum 0.2 -< mapFilterE getChangeSpeed cmdev - windowSize <- hold (100, 100) -< mapFilterE getResize cmdev + windowSize <- hold size -< mapFilterE getResize cmdev tick <- tickSignal -< time space <- engine initSpace -< gate tick playing diff --git a/Main.hs b/Main.hs index b13cd4c..5c166dc 100644 --- a/Main.hs +++ b/Main.hs @@ -6,6 +6,7 @@ import Graphics.Engine (initialSpace, run) import Graphics.Gloss import Graphics.GlossUtils (playYampa) +-- random space just to test things space :: ToroidalSpace Bool space = tabulate (\(x, y) -> (x + y `mod` 5) * 10 + x - y > 30) @@ -15,4 +16,4 @@ main = (InWindow "Conway's Game of Life" (200, 200) (10, 10)) black 30 - (run space) \ No newline at end of file + (run (200, 200) space) diff --git a/flake.lock b/flake.lock index e15f5a8..b1039cb 100644 --- a/flake.lock +++ b/flake.lock @@ -1,21 +1,5 @@ { "nodes": { - "flake-compat": { - "flake": false, - "locked": { - "lastModified": 1627913399, - "narHash": "sha256-hY8g6H2KFL8ownSiFeMOjwPC8P0ueXpCVEbxgda3pko=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "12c64ca55c1014cdc1b16ed5a804aa8576601ff2", - "type": "github" - }, - "original": { - "owner": "edolstra", - "repo": "flake-compat", - "type": "github" - } - }, "flake-utils": { "locked": { "lastModified": 1638122382, @@ -48,7 +32,6 @@ }, "root": { "inputs": { - "flake-compat": "flake-compat", "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } diff --git a/flake.nix b/flake.nix index 9b0d69c..d57e1bb 100644 --- a/flake.nix +++ b/flake.nix @@ -1,59 +1,54 @@ -# SPDX-FileCopyrightText: 2021 Serokell -# -# SPDX-License-Identifier: CC0-1.0 - { - description = "My haskell application"; + description = "Conway's Game of Life in Haskell"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs"; flake-utils.url = "github:numtide/flake-utils"; - - flake-compat.url = "github:edolstra/flake-compat"; - flake-compat.flake = false; }; outputs = { self, nixpkgs, flake-utils, ... }: flake-utils.lib.eachDefaultSystem (system: let + overlays = [ ]; pkgs = nixpkgs.legacyPackages.${system}; - - haskellPackages = pkgs.haskellPackages; - - jailbreakUnbreak = pkg: - pkgs.haskell.lib.doJailbreak (pkg.overrideAttrs (_: { meta = { }; })); - - packageName = "conways-game-of-life"; - execName = "gol"; - in { - packages.${packageName} = - haskellPackages.callCabal2nix packageName self rec { - # Dependency overrides go here + hp = pkgs.haskellPackages; # pkgs.haskell.packages.ghc921; + project = returnShellEnv: + hp.developPackage { + inherit returnShellEnv; + name = "conways-game-of-life"; + root = ./.; + withHoogle = false; + overrides = self: super: with pkgs.haskell.lib; { + # Use callCabal2nix to override Haskell dependencies here + # cf. https://tek.brick.do/K3VXJd8mEKO7 + # Example: + # > NanoID = self.callCabal2nix "NanoID" inputs.NanoID { }; + # Assumes that you have the 'NanoID' flake input defined. + }; + modifier = drv: + pkgs.haskell.lib.addBuildTools drv (with hp; [ + # Specify your build/dev dependencies here. + hlint + haskell-language-server + ormolu + + pkgs.mesa + pkgs.mesa_glu + pkgs.freeglut + ]); }; + in + { + # Used by `nix build` & `nix run` (prod exe) + defaultPackage = project false; - defaultPackage = self.packages.${system}.${packageName}; - - apps.${execName} = { + defaultApp = { type = "app"; - program = "${self.packages.${system}.${packageName}}/bin/${execName}"; + program = "${self.defaultPackage.${system}}/bin/${execName}"; }; - defaultApp = self.apps.${system}.${execName}; - - devShell = pkgs.mkShell { - buildInputs = with haskellPackages; [ - ghcid - cabal-install - hlint - pkgs.haskell-language-server - pkgs.ormolu - - pkgs.mesa - pkgs.mesa_glu - pkgs.freeglut - ]; - inputsFrom = builtins.attrValues self.packages.${system}; - }; + # Used by `nix develop` (dev shell) + devShell = project true; }); -} \ No newline at end of file +} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 81e3286..0000000 --- a/shell.nix +++ /dev/null @@ -1,8 +0,0 @@ -(import ( - let lock = builtins.fromJSON (builtins.readFile ./flake.lock); - in - fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - } -) { src = ./.; }).shellNix \ No newline at end of file