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