diff options
-rw-r--r-- | Com/Simatime/buildGhc.nix | 67 | ||||
-rw-r--r-- | Com/Simatime/buildGhcjs.nix | 80 | ||||
-rw-r--r-- | biz.nix | 118 | ||||
-rw-r--r-- | default.nix | 15 |
4 files changed, 125 insertions, 155 deletions
diff --git a/Com/Simatime/buildGhc.nix b/Com/Simatime/buildGhc.nix deleted file mode 100644 index 2b578b8..0000000 --- a/Com/Simatime/buildGhc.nix +++ /dev/null @@ -1,67 +0,0 @@ -nixpkgs: main: - -with nixpkgs; -with nixpkgs.lib; - -let - # provided by .envrc - root = builtins.getEnv "BIZ_ROOT"; - - # general functions to put in a lib - lines = s: strings.splitString "\n" s; - seq = ls: builtins.filter (x: x!= null) ls; - - # turn the file path into a Haskell module name - relpath = builtins.replaceStrings ["${root}/"] [""] (builtins.toString main); - module = builtins.replaceStrings ["/" ".hs"] ["." ""] relpath; - - # extract info from special comments - content = builtins.readFile main; - exe = builtins.head (lists.flatten (seq - (map (builtins.match "^-- : exe ([[:alnum:]._-]*)$") - (lines content)))); - deps = lists.flatten (seq - (map (builtins.match "^-- : dep ([[:alnum:]._-]*)$") - (lines content))); - - # do the build... - - depsToPackageSet = packageSet: deps: - map (s: builtins.getAttr s packageSet) deps; - - claySrc = pkgs.fetchFromGitHub { - owner = "sebastiaanvisser"; - repo = "clay"; - rev = "cc7729b1b42a79e261091ff7835f7fc2a7ae3cee"; - sha256 = "1vd67976lvi5l4qq18zy6j44apynkl44ps04p8vwfx4gzr895dyp"; - }; - - ghc865_ = pkgs.haskell.packages.ghc865.override (oldAttrs: { - overrides = with pkgs.haskell.lib; self: super: { - clay = self.callCabal2nix "clay" claySrc {}; - wai-middleware-metrics = dontCheck super.wai-middleware-metrics; - }; - }); - - ghc = ghc865_.ghcWithPackages (hp: depsToPackageSet hp deps); - -in stdenv.mkDerivation { - name = module; - version = "0"; - src = ../../.; # this is the git root - nativeBuildInputs = [ ghc ]; - strictDeps = true; - buildPhase = '' - # - mkdir -p $out/{bin,static} ${baseNameOf relpath} - # - # compile with ghc - # - ${ghc}/bin/ghc -Werror -i. \ - --make ${main} \ - -main-is ${module} \ - -o $out/bin/${exe} - ''; - # the install process was handled above - installPhase = "exit 0"; -} // { env = ghc; } diff --git a/Com/Simatime/buildGhcjs.nix b/Com/Simatime/buildGhcjs.nix deleted file mode 100644 index 0020fa4..0000000 --- a/Com/Simatime/buildGhcjs.nix +++ /dev/null @@ -1,80 +0,0 @@ -nixpkgs: main: - -with nixpkgs; -with nixpkgs.lib; - -let - # provided by .envrc - root = builtins.getEnv "BIZ_ROOT"; - - # general functions to put in a lib - lines = s: strings.splitString "\n" s; - seq = ls: builtins.filter (x: x!= null) ls; - - # turn the file path into a Haskell module name - relpath = builtins.replaceStrings ["${root}/"] [""] (builtins.toString main); - module = builtins.replaceStrings ["/" ".hs"] ["." ""] relpath; - - # extract info from special comments - content = builtins.readFile main; - exe = builtins.head (lists.flatten (seq - (map (builtins.match "^-- : exe ([[:alnum:]._-]*)$") - (lines content)))); - deps = lists.flatten (seq - (map (builtins.match "^-- : dep ([[:alnum:]._-]*)$") - (lines content))); - - # do the build... - - depsToPackageSet = packageSet: deps: - map (s: builtins.getAttr s packageSet) deps; - - claySrc = pkgs.fetchFromGitHub { - owner = "sebastiaanvisser"; - repo = "clay"; - rev = "cc7729b1b42a79e261091ff7835f7fc2a7ae3cee"; - sha256 = "1vd67976lvi5l4qq18zy6j44apynkl44ps04p8vwfx4gzr895dyp"; - }; - - # ghcjs-8.6.0.1 - ghcjs_ = pkgs.haskell.packages.ghcjs.override (oldAttrs: { - overrides = with pkgs.haskell.lib; self: super: { - QuickCheck = dontCheck super.QuickCheck; - base-compat-batteries = dontCheck super.http-types; - clay = dontCheck (self.callCabal2nix "clay" claySrc {}); - comonad = dontCheck super.comonad; - http-types = dontCheck super.http-types; - network-uri= dontCheck super.network-uri; - scientific = dontCheck super.scientific; # takes forever - servant = dontCheck super.servant; - tasty-quickcheck = dontCheck super.tasty-quickcheck; - time-compat = dontCheck super.time-compat; - }; - }); - - ghcjs = ghcjs_.ghcWithPackages (hp: depsToPackageSet hp deps); - -in stdenv.mkDerivation { - name = module; - version = "0"; - src = ../../.; # the git root - nativeBuildInputs = [ ghcjs ]; - strictDeps = true; - buildPhase = '' - # - mkdir -p $out/{bin,static} ${baseNameOf relpath} - # - # compile with ghcjs - # - ${ghcjs}/bin/ghcjs -Werror -i. \ - --make ${main} \ - -main-is ${module} \ - -o ${exe} - # - # optimize js output - # - ${pkgs.closurecompiler}/bin/closure-compiler \ - ${exe}.jsexe/all.js > $out/static/${exe} - ''; - installPhase = "exit 0"; -} // { env = ghcjs; } @@ -0,0 +1,118 @@ +{ nixpkgs }: + +with nixpkgs; +with nixpkgs.lib; + +let + # provided by .envrc + root = builtins.getEnv "BIZ_ROOT"; + + # general functions to put in a lib + lines = s: strings.splitString "\n" s; + seq = ls: builtins.filter (x: x!= null) ls; + depsToPackageSet = packageSet: deps: + map (s: builtins.getAttr s packageSet) deps; + + # do the build... + + claySrc = pkgs.fetchFromGitHub { + owner = "sebastiaanvisser"; + repo = "clay"; + rev = "cc7729b1b42a79e261091ff7835f7fc2a7ae3cee"; + sha256 = "1vd67976lvi5l4qq18zy6j44apynkl44ps04p8vwfx4gzr895dyp"; + }; + + ghc865_ = pkgs.haskell.packages.ghc865.override (oldAttrs: { + overrides = with pkgs.haskell.lib; self: super: { + clay = self.callCabal2nix "clay" claySrc {}; + wai-middleware-metrics = dontCheck super.wai-middleware-metrics; + }; + }); + + # ghcjs-8.6.0.1 + ghcjs_ = pkgs.haskell.packages.ghcjs.override (oldAttrs: { + overrides = with pkgs.haskell.lib; self: super: { + QuickCheck = dontCheck super.QuickCheck; + base-compat-batteries = dontCheck super.http-types; + clay = dontCheck (self.callCabal2nix "clay" claySrc {}); + comonad = dontCheck super.comonad; + http-types = dontCheck super.http-types; + network-uri= dontCheck super.network-uri; + scientific = dontCheck super.scientific; # takes forever + servant = dontCheck super.servant; + tasty-quickcheck = dontCheck super.tasty-quickcheck; + time-compat = dontCheck super.time-compat; + }; + }); + +in { + buildGhc = main: + let + relpath = builtins.replaceStrings ["${root}/"] [""] (builtins.toString main); + module = builtins.replaceStrings ["/" ".hs"] ["." ""] relpath; + content = builtins.readFile main; + exe = builtins.head (lists.flatten (seq + (map (builtins.match "^-- : exe ([[:alnum:]._-]*)$") + (lines content)))); + deps = lists.flatten (seq + (map (builtins.match "^-- : dep ([[:alnum:]._-]*)$") + (lines content))); + ghc = ghc865_.ghcWithPackages (hp: depsToPackageSet hp deps); + in stdenv.mkDerivation { + name = module; + version = "0"; + src = ./.; + nativeBuildInputs = [ ghc ]; + strictDeps = true; + buildPhase = '' + # + mkdir -p $out/{bin,static} ${baseNameOf relpath} + # + # compile with ghc + # + ${ghc}/bin/ghc -Werror -i. \ + --make ${main} \ + -main-is ${module} \ + -o $out/bin/${exe} + ''; + # the install process was handled above + installPhase = "exit 0"; + } // { env = ghc; }; + + buildGhcjs = main: + let + relpath = builtins.replaceStrings ["${root}/"] [""] (builtins.toString main); + module = builtins.replaceStrings ["/" ".hs"] ["." ""] relpath; + content = builtins.readFile main; + exe = builtins.head (lists.flatten (seq + (map (builtins.match "^-- : exe ([[:alnum:]._-]*)$") + (lines content)))); + deps = lists.flatten (seq + (map (builtins.match "^-- : dep ([[:alnum:]._-]*)$") + (lines content))); + ghcjs = ghcjs_.ghcWithPackages (hp: depsToPackageSet hp deps); + in stdenv.mkDerivation { + name = module; + version = "0"; + src = ./.; + nativeBuildInputs = [ ghcjs ]; + strictDeps = true; + buildPhase = '' + # + mkdir -p $out/{bin,static} ${baseNameOf relpath} + # + # compile with ghcjs + # + ${ghcjs}/bin/ghcjs -Werror -i. \ + --make ${main} \ + -main-is ${module} \ + -o ${exe} + # + # optimize js output + # + ${pkgs.closurecompiler}/bin/closure-compiler \ + ${exe}.jsexe/all.js > $out/static/${exe} + ''; + installPhase = "exit 0"; + } // { env = ghcjs; }; +} diff --git a/default.nix b/default.nix index 41a1f0b..753483d 100644 --- a/default.nix +++ b/default.nix @@ -4,9 +4,8 @@ let nixos = import "${nixpkgs-tar}/nixos"; # TODO(bsima): buildNixOS should be split into multiple functions that each # return one thing, instead of a single function that returns multiple things + biz = import ./biz.nix { inherit nixpkgs; }; buildOS = import ./Com/Simatime/buildOS.nix nixos; - buildGhc = import ./Com/Simatime/buildGhc.nix nixpkgs; - buildGhcjs = import ./Com/Simatime/buildGhcjs.nix nixpkgs; nixos-mailserver = let ver = "v2.3.0"; in builtins.fetchTarball { url = "https://gitlab.com/simple-nixos-mailserver/nixos-mailserver/-/archive/${ver}/nixos-mailserver-${ver}.tar.gz"; sha256 = "0lpz08qviccvpfws2nm83n7m2r8add2wvfg9bljx9yxx8107r919"; @@ -72,10 +71,10 @@ in rec { }; # Haskell targets # - Com.InfluencedByBooks.Server = buildGhc Com/InfluencedByBooks/Server.hs; - Com.InfluencedByBooks.Client = buildGhcjs Com/InfluencedByBooks/Client.hs; - Com.MusicMeetsComics.Server = buildGhc Com/MusicMeetsComics/Server.hs; - Com.MusicMeetsComics.Client = buildGhcjs Com/MusicMeetsComics/Client.hs; - Run.Que.Server = buildGhc ./Run/Que/Server.hs; - Run.Que.Website = buildGhc ./Run/Que/Website.hs; + Com.InfluencedByBooks.Server = biz.buildGhc Com/InfluencedByBooks/Server.hs; + Com.InfluencedByBooks.Client = biz.buildGhcjs Com/InfluencedByBooks/Client.hs; + Com.MusicMeetsComics.Server = biz.buildGhc Com/MusicMeetsComics/Server.hs; + Com.MusicMeetsComics.Client = biz.buildGhcjs Com/MusicMeetsComics/Client.hs; + Run.Que.Server = biz.buildGhc ./Run/Que/Server.hs; + Run.Que.Website = biz.buildGhc ./Run/Que/Website.hs; } |