on master help sign in
Merge pull request #291 from obsidiansystems/ts-dont-store-config

Don't put configs into the nix store

commitc8116e5a229c1b80e6efc2d519dcb74dde4dbaef authorLuigy Leon <luichi.19@gmail.com> dateWed 19 Dec 2018, 10:24 (8 years ago) parent66bf5a689e76a9
4 files changed+57−37
default.nix+26−28 lib/command/src/Obelisk/Command/Deploy.hs+27−7 lib/command/src/Obelisk/Command/Nix.hs+1 lib/executable-config/default.nix+3−2
default.nix+26−28
@@ -239,18 +239,17 @@ in rec {
239239 };
240240 };
241241
242− serverExe = backend: frontend: assets: config: optimizationLevel: version:
242+ serverExe = backend: frontend: assets: optimizationLevel: version:
243243 pkgs.runCommand "serverExe" {} ''
244244 mkdir $out
245245 set -eux
246246 ln -s "${haskellLib.justStaticExecutables backend}"/bin/* $out/
247247 ln -s "${mkAssets assets}" $out/static.assets
248− cp -r ${config} $out/config
249248 ln -s ${mkAssets (compressedJs frontend optimizationLevel)} $out/frontend.jsexe.assets
250249 echo ${version} > $out/version
251250 '';
252251
253− server = { exe, hostName, adminEmail, routeHost, enableHttps, config, version }@args:
252+ server = { exe, hostName, adminEmail, routeHost, enableHttps, version }@args:
254253 let
255254 nixos = import (pkgs.path + /nixos);
256255 in nixos {
@@ -266,8 +265,7 @@ in rec {
266265
267266 # An Obelisk project is a reflex-platform project with a predefined layout and role for each component
268267 project = base: projectDefinition:
269− let configPath = base + "/config";
270− projectOut = sys: (getReflexPlatform sys).project (args@{ nixpkgs, ... }:
268+ let projectOut = sys: (getReflexPlatform sys).project (args@{ nixpkgs, ... }:
271269 let mkProject = { android ? null #TODO: Better error when missing
272270 , ios ? null #TODO: Better error when missing
273271 , packages ? {}
@@ -300,7 +298,21 @@ in rec {
300298 privateConfigDirs = ["config/backend"];
301299 injectableConfig = builtins.filterSource (path: _:
302300 !(lib.lists.any (x: hasPrefix (toString base + "/" + toString x) (toString path)) privateConfigDirs)
303− ) configPath;
301+ );
302+ __android = configPath: {
303+ ${if android == null then null else frontendName} = {
304+ executableName = "frontend";
305+ ${if builtins.pathExists staticFiles then "assets" else null} =
306+ nixpkgs.obeliskExecutableConfig.platforms.android.inject (injectableConfig configPath) processedStatic.symlinked;
307+ } // android;
308+ };
309+ __ios = configPath: {
310+ ${if ios == null then null else frontendName} = {
311+ executableName = "frontend";
312+ ${if builtins.pathExists staticFiles then "staticSrc" else null} =
313+ nixpkgs.obeliskExecutableConfig.platforms.ios.inject (injectableConfig configPath) processedStatic.symlinked;
314+ } // ios;
315+ };
304316 in {
305317 inherit shellToolOverrides tools withHoogle;
306318 overrides = totalOverrides;
@@ -320,39 +332,25 @@ in rec {
320332 commonName
321333 ];
322334 };
323− android = {
324− ${if android == null then null else frontendName} = {
325− executableName = "frontend";
326− ${if builtins.pathExists staticFiles then "assets" else null} =
327− nixpkgs.obeliskExecutableConfig.platforms.android.inject injectableConfig processedStatic.symlinked;
328− } // android;
329− };
330− ios = {
331− ${if ios == null then null else frontendName} = {
332− executableName = "frontend";
333− ${if builtins.pathExists staticFiles then "staticSrc" else null} =
334− nixpkgs.obeliskExecutableConfig.platforms.ios.inject injectableConfig processedStatic.symlinked;
335− } // ios;
336− };
337− passthru = { inherit android ios packages overrides tools shellToolOverrides withHoogle staticFiles staticFilesImpure __closureCompilerOptimizationLevel; };
335+ android = __android null;
336+ ios = __ios null;
337+ passthru = { inherit android ios packages overrides tools shellToolOverrides withHoogle staticFiles staticFilesImpure __closureCompilerOptimizationLevel processedStatic __ios __android; };
338338 };
339339 in mkProject (projectDefinition args));
340− serverOn = sys: config: version: serverExe
340+ serverOn = sys: version: serverExe
341341 (projectOut sys).ghc.backend
342342 (projectOut system).ghcjs.frontend
343343 (projectOut sys).passthru.staticFiles
344− config
345344 (projectOut sys).passthru.__closureCompilerOptimizationLevel
346345 version;
347346 linuxExe = serverOn "x86_64-linux";
348347 dummyVersion = "Version number is only available for deployments";
349348 in projectOut system // {
350349 linuxExeConfigurable = linuxExe;
351− linuxExe = linuxExe (base + "/config") dummyVersion;
352− exe = serverOn system (base + "/config") dummyVersion;
353− server = args@{ hostName, adminEmail, routeHost, enableHttps, config, version }: let
354− injectableConfig = builtins.filterSource (path: _: !(lib.hasPrefix (toString config + "/backend") (toString path))) config;
355− in server (args // { exe = linuxExe injectableConfig version; });
350+ linuxExe = linuxExe dummyVersion;
351+ exe = serverOn system dummyVersion;
352+ server = args@{ hostName, adminEmail, routeHost, enableHttps, version }:
353+ server (args // { exe = linuxExe version; });
356354 obelisk = import (base + "/.obelisk/impl") {};
357355 };
358356 haskellPackageSets = {
lib/command/src/Obelisk/Command/Deploy.hs+27−7
@@ -123,7 +123,6 @@ deployPush deployPath getNixBuilders = do
123123 , strArg "routeHost" routeHost
124124 , strArg "version" version
125125 , boolArg "enableHttps" enableHttps
126− , rawArg "config" $ deployPath </> "config"
127126 ]
128127 & nixCmdConfig_builders .~ builders
129128 pure result
@@ -133,6 +132,14 @@ deployPush deployPath getNixBuilders = do
133132 callProcess'
134133 (Map.fromList [("NIX_SSHOPTS", unwords sshOpts)])
135134 "nix-copy-closure" ["-v", "--to", "root@" <> host, "--gzip", outputPath]
135+ withSpinner "Uploading config" $ ifor_ buildOutputByHost $ \host _ -> do
136+ callProcessAndLogOutput (Notice, Warning) $
137+ proc "rsync"
138+ [ "-e ssh " <> unwords sshOpts
139+ , "-qarvz"
140+ , deployPath </> "config"
141+ , "root@" <> host <> ":/var/lib/backend"
142+ ]
136143 --TODO: Create GC root so we're sure our closure won't go away during this time period
137144 withSpinner "Switching to new configuration" $ ifor_ buildOutputByHost $ \host outputPath -> do
138145 callProcessAndLogOutput (Notice, Warning) $
@@ -185,6 +192,7 @@ renderPlatformDeployment = \case
185192deployMobile :: MonadObelisk m => PlatformDeployment -> [String] -> m ()
186193deployMobile platform mobileArgs = withProjectRoot "." $ \root -> do
187194 let srcDir = root </> "src"
195+ configDir = root </> "config"
188196 exists <- liftIO $ doesDirectoryExist srcDir
189197 unless exists $ failWith "ob test should be run inside of a deploy directory"
190198 nixBuildTarget <- case platform of
@@ -217,16 +225,28 @@ deployMobile platform mobileArgs = withProjectRoot "." $ \root -> do
217225 Right conf -> do
218226 let nvset = toValue @(HM.HashMap Text (NValueNF Identity)) @Identity @(NValueNF Identity) $ keytoolToAndroidConfig conf
219227 return $ printNix $ runIdentity nvset
228+ let expr = mconcat
229+ [ "with (import ", srcDir, " {});"
230+ , "android.frontend.override (drv: { "
231+ , "releaseKey = (if builtins.isNull drv.releaseKey then {} else drv.releaseKey) // " <> releaseKey <> "; "
232+ , "staticSrc = (passthru.__android ", configDir, ").frontend.staticSrc;"
233+ , "})"
234+ ]
235+ return $ Target
236+ { _target_path = Nothing
237+ , _target_attr = Nothing
238+ , _target_expr = Just expr
239+ }
240+ IOS -> do
241+ let expr = mconcat
242+ [ "with (import ", srcDir, " {});"
243+ , "ios.frontend.override (_: { staticSrc = (passthru.__ios ", configDir, ").frontend.staticSrc; })"
244+ ]
220245 return $ Target
221246 { _target_path = Nothing
222247 , _target_attr = Nothing
223− , _target_expr = Just $ "with (import " <> srcDir <> " {}); " <> renderPlatformDeployment platform <> ".frontend.override (drv: { releaseKey = (if builtins.isNull drv.releaseKey then {} else drv.releaseKey) // " <> releaseKey <> "; })"
248+ , _target_expr = Just expr
224249 }
225− IOS -> return $ Target
226− { _target_path = Nothing
227− , _target_attr = Just "ios.frontend"
228− , _target_expr = Nothing
229− }
230250 result <- nixCmd $ NixCmd_Build $ def
231251 & nixBuildConfig_outLink .~ OutLink_None
232252 & nixCmdConfig_target .~ nixBuildTarget
lib/command/src/Obelisk/Command/Nix.hs+1
@@ -15,6 +15,7 @@ module Obelisk.Command.Nix
1515 , nixCmdConfig_args
1616 , nixCmdConfig_builders
1717 , NixBuildConfig (..)
18+ , nixBuildConfig_common
1819 , nixBuildConfig_outLink
1920 , NixInstantiateConfig (..)
2021 , nixInstantiateConfig_eval
lib/executable-config/default.nix+3−2
@@ -5,17 +5,18 @@
55{ nixpkgs
66, filterGitSource # TODO define this in obelisk
77}:
8−let injectConfig = config: assets: nixpkgs.runCommand "inject-config" {} ''
8+let injectConfig = config: assets: nixpkgs.runCommand "inject-config" {} (''
99 set -x
1010 mkdir -p $out
1111 cp --no-preserve=mode -Lr "${assets}" $out/static
1212 chmod +w "$out"
13+ '' + nixpkgs.lib.optionalString (!(builtins.isNull config)) ''
1314 if ! mkdir $out/config; then
1415 2>&1 echo config directory already exists or could not be created
1516 exit 1
1617 fi
1718 cp -a "${config}"/* "$out/config"
18− '';
19+ '');
1920in with nixpkgs.haskell.lib; {
2021 haskellPackage = self: self.callPackage (filterGitSource ./lookup) {};
2122 platforms = {