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" ''
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
$(if [[ $RESULT == "failed" ]]; then echo -e 'maralorn'; ${pkgs.curl}/bin/curl -m1 -s $LAMINAR_URL/log/$JOB/$RUN | tail; fi)
EOF

View file

@ -12,7 +12,8 @@ let
cd kassandra
git show -q
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."
nix-jobs realise $drv
'';

View file

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

View file

@ -22,8 +22,10 @@ let
value = pkgs.writeShellScript "test-${host}-home-config.run" ''
${common}
${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
export FLAGS=""
${pkgs.test-home-config}/bin/test-home-config $REPODIR ${host}
'';
});
@ -32,8 +34,10 @@ let
value = pkgs.writeShellScript "test-${host}-system-config.run" ''
${common}
${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
export FLAGS=""
${pkgs.test-system-config}/bin/test-system-config $REPODIR ${host}
'';
});

View file

@ -6,14 +6,16 @@ let
systems = [ "apollo" "hera" ];
homes = self.lib.attrNames (import ../home-manager/machines.nix);
imports = [ "Control.Exception (onException)" ];
haskellBody = name: commandline: ''
haskellBody = name: drv: target: ''
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 -> nixpkgsChannel) <- nix_instantiate "--eval" "-E" ([i|(import #{configDir}/channels.nix).#{hostname}.nixpkgs-channel|] :: String) |> captureTrim
paths <- aNixPath homeManagerChannel nixpkgsChannel (toText configDir)
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.|]
'';
in {
@ -22,15 +24,13 @@ in {
name = "test-system-config";
inherit bins;
inherit imports;
} (haskellBody "system" ''
nix_build $ buildSystemParams ++ paths ++ ["-I", [i|nixos-config=#{configDir}/nixos/machines/#{hostname}/configuration.nix|], "-o", [i|result-system-#{hostname}|]] ++ fmap toString args'');
} (haskellBody "system" ''buildSystemParams ++ paths ++ ["-I", [i|nixos-config=#{configDir}/nixos/machines/#{hostname}/configuration.nix|]]'' "[i|result-system-#{hostname}|]");
test-home-config = self.writeHaskellScript {
name = "test-home-config";
inherit bins;
inherit imports;
} (haskellBody "home" ''
nix_build $ paths ++ [[i|#{configDir}/home-manager/target.nix|], "-A", hostname, "-o", [i|result-home-manager-#{hostname}|]] ++ fmap toString args'');
} (haskellBody "home" ''paths ++ [[i|#{configDir}/home-manager/target.nix|], "-A", hostname]'' "[i|result-home-manager-#{hostname}|]");
test-config = self.writeHaskellScript {
name = "test-config";