diff --git a/nixos/roles/laminar/default.nix b/nixos/roles/laminar/default.nix index 33e040d2..9dc54300 100644 --- a/nixos/roles/laminar/default.nix +++ b/nixos/roles/laminar/default.nix @@ -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 <) , (|>) ) 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. Can’t 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 diff --git a/nixos/roles/laminar/test-config.nix b/nixos/roles/laminar/test-config.nix index bf8fbc5a..52b7e1ec 100644 --- a/nixos/roles/laminar/test-config.nix +++ b/nixos/roles/laminar/test-config.nix @@ -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} ''; }); diff --git a/overlays/testing.nix b/overlays/testing.nix index 5670dad4..32900c29 100644 --- a/overlays/testing.nix +++ b/overlays/testing.nix @@ -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";