Improving nix-jobs performance
This commit is contained in:
parent
3ce4ce6ba8
commit
a21a70bac2
|
@ -4,8 +4,10 @@ let
|
|||
stateDir = "/var/lib/laminar";
|
||||
cfgDir = "${stateDir}/cfg";
|
||||
cfg = config.services.laminar;
|
||||
cacheResult = "${pkgs.writeShellScript "cache-result-as-root"
|
||||
''echo "Cached build-result $1 to $(${pkgs.nix}/bin/nix-store -r --indirect --add-root "/var/cache/gc-links/$2" "$1")."''}";
|
||||
cacheResult = "${pkgs.writeShellScript "cache-result-as-root" ''
|
||||
echo "Cached build-result $1 to"
|
||||
${pkgs.nix}/bin/nix-store -r --indirect --add-root "/var/cache/gc-links/$2" "$1"
|
||||
''}";
|
||||
in {
|
||||
options = {
|
||||
services.laminar = {
|
||||
|
|
|
@ -33,6 +33,7 @@ import qualified Data.Text as T
|
|||
import Data.Time ( diffUTCTime
|
||||
, getCurrentTime
|
||||
)
|
||||
import qualified Data.Map as Map
|
||||
import Relude
|
||||
import Say ( say
|
||||
, sayErr
|
||||
|
@ -73,6 +74,7 @@ import System.Posix.IO ( OpenFileFlags(exclusive)
|
|||
, fdWrite
|
||||
, openFd
|
||||
)
|
||||
import System.IO.Unsafe
|
||||
|
||||
|
||||
load Absolute ["laminarc", "nix-store"]
|
||||
|
@ -113,6 +115,10 @@ runningPath, resultPath :: Text -> String
|
|||
runningPath p = [i|#{runningDir}/#{drvBasename p}|]
|
||||
resultPath p = [i|#{resultDir}/#{drvBasename p}|]
|
||||
|
||||
{-# NOINLINE depMap #-}
|
||||
depMap :: TVar (Map Text (Seq Text))
|
||||
depMap = unsafePerformIO $ newTVarIO mempty
|
||||
|
||||
-- Bool means derivation itself needs to be build
|
||||
getDependenciesFromNix :: Text -> IO (Seq Text)
|
||||
getDependenciesFromNix derivationName = do
|
||||
|
@ -128,8 +134,11 @@ needsBuild derivationName = do
|
|||
|
||||
nixStoreRealiseDryRun :: Text -> IO (Seq Text)
|
||||
nixStoreRealiseDryRun derivationName = do
|
||||
process
|
||||
<$> (nix_store "-r" derivationName "--dry-run" &!> StdOut |> captureTrim)
|
||||
maybeDeps <- Map.lookup derivationName <$> readTVarIO depMap
|
||||
deps <- maybe (process
|
||||
<$> (nix_store "-r" derivationName "--dry-run" &!> StdOut |> captureTrim)) pure maybeDeps
|
||||
whenNothing_ maybeDeps $ atomically $ modifyTVar' depMap (Map.insert derivationName deps)
|
||||
pure deps
|
||||
where
|
||||
process =
|
||||
fromList
|
||||
|
|
|
@ -11,7 +11,7 @@ let
|
|||
say [i|Trying to build ${name} config for #{hostname}.|]
|
||||
(Text.dropAround ('"' ==) . decodeUtf8 . trim -> derivationName) <- (nix_instantiate $ ${drv}) |> captureTrim
|
||||
exe "nix-jobs" ["realise", toString derivationName]
|
||||
laminarc ["set", [i|RESULTDRV=#{derivationName}|]]
|
||||
writeFileText "derivation" derivationName
|
||||
say [i|Build of ${name} config for #{hostname} was successful.|]
|
||||
'';
|
||||
test-system-config = pkgs.writeHaskellScript {
|
||||
|
@ -52,6 +52,7 @@ let
|
|||
git -C $REPODIR submodule update --init
|
||||
export FLAGS=""
|
||||
${test-home-config}/bin/test-home-config $REPODIR ${host}
|
||||
laminarc set "RESULTDRV=$(cat ./derivation)"
|
||||
'';
|
||||
});
|
||||
mkSystemJob = (host: {
|
||||
|
@ -64,6 +65,7 @@ let
|
|||
git -C $REPODIR submodule update --init
|
||||
export FLAGS=""
|
||||
${test-system-config}/bin/test-system-config $REPODIR ${host}
|
||||
laminarc set "RESULTDRV=$(cat ./derivation)"
|
||||
'';
|
||||
});
|
||||
deployCommand = "${pkgs.writeShellScript "deploy-system-config"
|
||||
|
@ -113,8 +115,8 @@ in {
|
|||
in ''
|
||||
/run/wrappers/bin/sudo -u ${user} git -C /etc/nixos pull --ff-only
|
||||
/run/wrappers/bin/sudo -u ${user} git -C /etc/nixos submodule update --init
|
||||
/var/cache/gc-links/result-system-hera/bin/switch-to-configuration switch
|
||||
/run/wrappers/bin/sudo -u ${user} /var/cache/gc-links/result-home-manager-hera/default/activate
|
||||
/var/cache/gc-links/system-config-hera/bin/switch-to-configuration switch
|
||||
/run/wrappers/bin/sudo -u ${user} /var/cache/gc-links/home-config-hera/default/activate
|
||||
'';
|
||||
};
|
||||
bump-config = {
|
||||
|
|
Loading…
Reference in a new issue