1
0
Fork 0

Fine tune ci

This commit is contained in:
Malte Brandy 2021-01-09 03:31:25 +01:00
parent 1f5ac61eef
commit e50ac47e7f
5 changed files with 34 additions and 16 deletions

View file

@ -40,7 +40,7 @@ in {
}; };
after = pkgs.writeShellScript "after-all-jobs-script" '' after = pkgs.writeShellScript "after-all-jobs-script" ''
LAMINAR_URL="https://ci.maralorn.de" LAMINAR_URL="https://ci.maralorn.de"
${pkgs.matrix-commander}/bin/matrix-commander -c ${stateDir}/matrix-credentials.json -s ${stateDir}/matrix-secrets-store <<EOF ${pkgs.matrix-commander}/bin/matrix-commander -c ${stateDir}/matrix-credentials.json -s ./store <<EOF
$JOB #$RUN: $RESULT $JOB #$RUN: $RESULT
$(if [[ $RESULT == "failed" ]]; then echo -e 'maralorn'; ${pkgs.curl}/bin/curl -m1 -s $LAMINAR_URL/log/$JOB/$RUN | tail; fi) $(if [[ $RESULT == "failed" ]]; then echo -e 'maralorn'; ${pkgs.curl}/bin/curl -m1 -s $LAMINAR_URL/log/$JOB/$RUN | tail; fi)
EOF EOF

View file

@ -12,7 +12,8 @@ let
cd kassandra cd kassandra
git show -q git show -q
echo "Evaluating nix-expression." echo "Evaluating nix-expression."
drv=$(readlink -f $(nix-instantiate release.nix -A ${name} --add-root ./drv --indirect)) export FLAGS='--builders @/etc/nix/machines --max-jobs 1'
drv=$(readlink -f $(nix-instantiate release.nix -A ${name} --add-root ./drv --indirect $FLAGS))
echo "Evaluation done." echo "Evaluation done."
nix-jobs realise $drv nix-jobs realise $drv
''; '';

View file

@ -46,10 +46,13 @@ import Shh ( (&!>)
, (|>) , (|>)
) )
import System.Directory ( createDirectoryIfMissing import System.Directory ( createDirectoryIfMissing
, doesFileExist
, getModificationTime , getModificationTime
, removeFile , removeFile
) )
import System.Environment ( getArgs ) import System.Environment ( getArgs
, getEnv
)
import System.FSNotify ( Event(Removed) import System.FSNotify ( Event(Removed)
, watchDir , watchDir
, withManager , withManager
@ -130,14 +133,22 @@ nixStoreRealiseDryRun derivationName = do
job :: Text -> IO () job :: Text -> IO ()
job derivationName = do job derivationName = do
when (T.null derivationName) $ do
sayErr [i|Empty derivationName. Cant realise that.|]
exitFailure
say [i|Building #{derivationName}.|] say [i|Building #{derivationName}.|]
whenM (not <$> doesFileExist (runningPath derivationName)) $ do
sayErr
[i|No file found at #{runningPath derivationName}. Did you start realise-here outside of the nix-build job?|]
exitFailure
let setResult result = do let setResult result = do
createDirectoryIfMissing True resultDir createDirectoryIfMissing True resultDir
writeFileText (resultPath derivationName) (show result) writeFileText (resultPath derivationName) (show result)
removeFile (runningPath derivationName) removeFile (runningPath derivationName)
ensureDeps Children derivationName ensureDeps Children derivationName
flags <- filter (/= mempty) . splitOn " " . toText <$> getEnv "FLAGS"
catch catch
(nixStoreRealise derivationName) (nixStoreRealise derivationName flags)
(\(err :: SomeException) -> do (\(err :: SomeException) -> do
setResult Failure setResult Failure
sayErr [i|nix-build failed with error #{err}.|] sayErr [i|nix-build failed with error #{err}.|]
@ -146,8 +157,8 @@ job derivationName = do
setResult Success setResult Success
say [i|Build for #{derivationName} successful.|] say [i|Build for #{derivationName} successful.|]
nixStoreRealise :: Text -> IO () nixStoreRealise :: Text -> [Text] -> IO ()
nixStoreRealise = nix_store "-r" nixStoreRealise name flags = nix_store (["-r", name] <> flags)
ensureDeps :: ReportLevel -> Text -> IO () ensureDeps :: ReportLevel -> Text -> IO ()
ensureDeps level derivationName = do ensureDeps level derivationName = do
@ -171,11 +182,13 @@ tryQueue derivationName = handleExisting $ do
$ throw $ throw
[i|Wrote 0 bytes of jobName "#{jobName}" to #{runningPath derivationName}|] [i|Wrote 0 bytes of jobName "#{jobName}" to #{runningPath derivationName}|]
pure . Just $ jobName pure . Just $ jobName
startJob = startJob = do
flags <- getEnv "FLAGS"
decodeUtf8 decodeUtf8
<$> ( laminarc "queue" <$> ( laminarc "queue"
"nix-build" "nix-build"
([i|DERIVATION=#{derivationName}|] :: Text) ([i|DERIVATION=#{derivationName}|] :: Text)
([i|FLAGS=#{flags}|] :: Text)
|> captureTrim |> captureTrim
) )
handleExisting = handleJust handleExisting = handleJust

View file

@ -22,8 +22,10 @@ let
value = pkgs.writeShellScript "test-${host}-home-config.run" '' value = pkgs.writeShellScript "test-${host}-home-config.run" ''
${common} ${common}
${checkout} ${checkout}
${pkgs.test-home-config}/bin/test-home-config $REPODIR ${host} --builders "@/etc/nix/machines" --max-jobs 1 export FLAGS='--builders @/etc/nix/machines --max-jobs 1'
${pkgs.test-home-config}/bin/test-home-config $REPODIR ${host}
git -C $REPODIR submodule update --init git -C $REPODIR submodule update --init
export FLAGS=""
${pkgs.test-home-config}/bin/test-home-config $REPODIR ${host} ${pkgs.test-home-config}/bin/test-home-config $REPODIR ${host}
''; '';
}); });
@ -32,8 +34,10 @@ let
value = pkgs.writeShellScript "test-${host}-system-config.run" '' value = pkgs.writeShellScript "test-${host}-system-config.run" ''
${common} ${common}
${checkout} ${checkout}
${pkgs.test-system-config}/bin/test-system-config $REPODIR ${host} --builders "@/etc/nix/machines" --max-jobs 1 export FLAGS='--builders @/etc/nix/machines --max-jobs 1'
${pkgs.test-system-config}/bin/test-system-config $REPODIR ${host}
git -C $REPODIR submodule update --init git -C $REPODIR submodule update --init
export FLAGS=""
${pkgs.test-system-config}/bin/test-system-config $REPODIR ${host} ${pkgs.test-system-config}/bin/test-system-config $REPODIR ${host}
''; '';
}); });

View file

@ -6,14 +6,16 @@ let
systems = [ "apollo" "hera" ]; systems = [ "apollo" "hera" ];
homes = self.lib.attrNames (import ../home-manager/machines.nix); homes = self.lib.attrNames (import ../home-manager/machines.nix);
imports = [ "Control.Exception (onException)" ]; imports = [ "Control.Exception (onException)" ];
haskellBody = name: commandline: '' haskellBody = name: drv: target: ''
main = do main = do
(configDir:hostname:args) <- getArgs (configDir:hostname:_) <- getArgs
(Text.dropAround ('"' ==) . decodeUtf8 . trim -> homeManagerChannel) <- nix_instantiate "--eval" "-E" ([i|(import #{configDir}/channels.nix).#{hostname}.home-manager-channel|] :: String) |> captureTrim (Text.dropAround ('"' ==) . decodeUtf8 . trim -> homeManagerChannel) <- nix_instantiate "--eval" "-E" ([i|(import #{configDir}/channels.nix).#{hostname}.home-manager-channel|] :: String) |> captureTrim
(Text.dropAround ('"' ==) . decodeUtf8 . trim -> nixpkgsChannel) <- nix_instantiate "--eval" "-E" ([i|(import #{configDir}/channels.nix).#{hostname}.nixpkgs-channel|] :: String) |> captureTrim (Text.dropAround ('"' ==) . decodeUtf8 . trim -> nixpkgsChannel) <- nix_instantiate "--eval" "-E" ([i|(import #{configDir}/channels.nix).#{hostname}.nixpkgs-channel|] :: String) |> captureTrim
paths <- aNixPath homeManagerChannel nixpkgsChannel (toText configDir) paths <- aNixPath homeManagerChannel nixpkgsChannel (toText configDir)
say [i|Trying to build ${name} config for #{hostname}.|] say [i|Trying to build ${name} config for #{hostname}.|]
${commandline} (Text.dropAround ('"' ==) . decodeUtf8 . trim -> derivationName) <- (nix_instantiate $ ${drv}) |> captureTrim
exe "nix-jobs" ["realise", toString derivationName]
nix_store ["-r", toString derivationName, "--indirect", "--add-root", ${target}]
say [i|Build of ${name} config for #{hostname} was successful.|] say [i|Build of ${name} config for #{hostname} was successful.|]
''; '';
in { in {
@ -22,15 +24,13 @@ in {
name = "test-system-config"; name = "test-system-config";
inherit bins; inherit bins;
inherit imports; inherit imports;
} (haskellBody "system" '' } (haskellBody "system" ''buildSystemParams ++ paths ++ ["-I", [i|nixos-config=#{configDir}/nixos/machines/#{hostname}/configuration.nix|]]'' "[i|result-system-#{hostname}|]");
nix_build $ buildSystemParams ++ paths ++ ["-I", [i|nixos-config=#{configDir}/nixos/machines/#{hostname}/configuration.nix|], "-o", [i|result-system-#{hostname}|]] ++ fmap toString args'');
test-home-config = self.writeHaskellScript { test-home-config = self.writeHaskellScript {
name = "test-home-config"; name = "test-home-config";
inherit bins; inherit bins;
inherit imports; inherit imports;
} (haskellBody "home" '' } (haskellBody "home" ''paths ++ [[i|#{configDir}/home-manager/target.nix|], "-A", hostname]'' "[i|result-home-manager-#{hostname}|]");
nix_build $ paths ++ [[i|#{configDir}/home-manager/target.nix|], "-A", hostname, "-o", [i|result-home-manager-#{hostname}|]] ++ fmap toString args'');
test-config = self.writeHaskellScript { test-config = self.writeHaskellScript {
name = "test-config"; name = "test-config";