on master help sign in
Move profiledObRun script to default.nix

This file is just a static nix script. We can avoid hereDoc and just hit the attr directly. In addition, add the skeleton’s profiledObRun to the release.nix.

commit8a2e1ab5a63ea1f63964a496fdf3329101997cf4 authorMatthew Bauer <mjbauer95@gmail.com> dateThu 20 Feb 2020, 14:02 (7 years ago) parent876957b
3 files changed+30−32
all-builds.nix+1 default.nix+26−1 lib/command/src/Obelisk/Command/Run.hs+3−31
all-builds.nix+1
@@ -68,6 +68,7 @@ let
6868 iosSkeleton = (import ./skeleton { inherit obelisk; }).ios.frontend;
6969 nameSuffix = if profiling then "profiled" else "unprofiled";
7070 packages = {
71+ skeletonProfiledObRun = skeleton.profiledObRun;
7172 inherit
7273 command
7374 serverSkeletonShell
default.nix+26−1
@@ -374,7 +374,32 @@ in rec {
374374 linuxExe = serverOn (projectOut "x86_64-linux");
375375 dummyVersion = "Version number is only available for deployments";
376376 in mainProjectOut // {
377− profiled = projectOut { inherit system; enableLibraryProfiling = true; };
377+
378+ profiledObRun = let
379+ profiled = projectOut { inherit system; enableLibraryProfiling = true; };
380+ exeSource = builtins.toFile "ob-run.hs" ''
381+ module Main where
382+
383+ import Control.Exception
384+ import Reflex.Profiled
385+ import System.Environment
386+
387+ import qualified Obelisk.Run
388+ import qualified Frontend
389+ import qualified Backend
390+
391+ main :: IO ()
392+ main = do
393+ args <- getArgs
394+ let port = read $ args !! 0
395+ assets = args !! 1
396+ profileFile = (args !! 2) <> ".rprof"
397+ Obelisk.Run.run port (Obelisk.Run.runServeAsset assets) Backend.backend Frontend.frontend `finally` writeProfilingData profileFile
398+ '';
399+ in nixpkgs.runCommand "ob-run" {
400+ buildInputs = [ (profiled.ghc.ghcWithPackages (p: [ p.backend p.frontend])) ];
401+ } "ghc -x hs -prof -fno-prof-auto -threaded ${exeSource} -o $out";
402+
378403 linuxExeConfigurable = linuxExe;
379404 linuxExe = linuxExe dummyVersion;
380405 exe = serverOn mainProjectOut dummyVersion;
lib/command/src/Obelisk/Command/Run.hs+3−31
@@ -23,7 +23,6 @@ import Data.Map (Map)
2323import qualified Data.Map as Map
2424import Data.Maybe
2525import qualified Data.Set as Set
26−import Data.String.Here (hereLit)
2726import Data.Text (Text)
2827import qualified Data.Text as T
2928import Data.Time.Clock (getCurrentTime)
@@ -97,9 +96,9 @@ profile profileBasePattern rtsFlags = withProjectRoot "." $ \root -> do
9796 exePath <- nixCmd $ NixCmd_Build $ def
9897 & nixBuildConfig_outLink .~ OutLink_None
9998 & nixCmdConfig_target .~ Target
100− { _target_path = Nothing
101− , _target_attr = Nothing
102− , _target_expr = Just nixBuildExpr }
99+ { _target_path = Just "."
100+ , _target_attr = Just "profiledObRun"
101+ , _target_expr = Nothing }
103102 assets <- findProjectAssets root
104103 putLog Debug $ "Assets impurely loaded from: " <> assets
105104 freePort <- getFreePort
@@ -112,33 +111,6 @@ profile profileBasePattern rtsFlags = withProjectRoot "." $ \root -> do
112111 ] <> rtsFlags
113112 <> [ "-RTS" ]
114113 void $ waitForProcess ph
115− where
116− nixBuildExpr = [hereLit|
117−with (import ./. {});
118−let
119− exeSource = obelisk.nixpkgs.writeText "ob-run" ''
120−module Main where
121−
122−import Control.Exception
123−import Reflex.Profiled
124−import System.Environment
125−
126−import qualified Obelisk.Run
127−import qualified Frontend
128−import qualified Backend
129−
130−main :: IO ()
131−main = do
132− args <- getArgs
133− let port = read $ args !! 0
134− assets = args !! 1
135− profileFile = (args !! 2) <> ".rprof"
136− Obelisk.Run.run port (Obelisk.Run.runServeAsset assets) Backend.backend Frontend.frontend `finally` writeProfilingData profileFile
137− '';
138−in obelisk.nixpkgs.runCommand "ob-run" {
139− buildInputs = [ (profiled.ghc.ghcWithPackages (p: [ p.backend p.frontend])) ];
140−} "ghc -x hs -prof -fno-prof-auto -threaded ${exeSource} -o $out"
141−|]
142114
143115run
144116 :: MonadObelisk m