1
0
Fork 0

Simplify update code

This commit is contained in:
Malte 2023-02-02 15:01:49 +01:00
parent 76eb0d78c2
commit 54209d661f
2 changed files with 8 additions and 27 deletions

View file

@ -9,50 +9,31 @@
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wall -Werror -Wno-missing-signatures -Wno-type-defaults -Wno-orphans #-}
{-# OPTIONS_GHC -Wall -Werror -Wno-missing-signatures -Wno-type-defaults #-}
import Control.Concurrent.Async
import Data.String.Interpolate
import Data.Text (stripPrefix)
import Language.Haskell.TH.Syntax
import Relude
import Say
import Shh
import System.Environment (getEnv, setEnv)
import System.Environment (getEnv)
load Absolute ["laminarc", "git", "nix"]
repo = "git@hera.m-0.eu:nixos-config"
jobs :: [String]
jobs =
$$( bindCode
( runIO $ do
homes <- getEnv "HOMES"
systems <- getEnv "SYSTEMS"
let ret =
((\x -> [i|system-config-#{x}|]) <$> (words . toText) systems)
<> ((\x -> [i|home-config-#{x}|]) <$> (words . toText) homes)
say [i|Found jobs #{ret}|]
pure ret
)
liftTyped
)
deployCommand :: String
deployCommand = $$(bindCode (runIO $ getEnv "DEPLOY") liftTyped)
main = do
let process = fromMaybe "main" . (stripPrefix "refs/heads/" . toText =<<)
branch <- process <$> lookupEnv "BRANCH"
jobId <- getEnv "JOB"
runId <- getEnv "RUN"
git "clone" repo "."
git "checkout" (toString branch)
setEnv "LAMINAR_REASON" [i|Building config branch #{branch} for all systems in #{jobId}:#{runId}|]
say [i|Starting builds of branch #{branch} for all systems.|]
concurrently_ (mapConcurrently_ (\x -> laminarc ["run", x, [i|BRANCH=#{branch}|]]) jobs) $ nix "flake" "check"
say [i|Builds succeeded.|]
say "Running checks"
nix "flake" "check"
say "Checks succeeded"
when (branch == "main") $ do
say [i|Deploying new config to localhost.|]
exe "/run/wrappers/bin/sudo" deployCommand

View file

@ -135,7 +135,7 @@ in {
];
systemd.services = {
update-config = {
path = [pkgs.git pkgs.nix pkgs.openssh];
path = [pkgs.git pkgs.nix pkgs.openssh pkgs.nixos-rebuild];
restartIfChanged = false;
unitConfig.X-StopOnRemoval = false;
serviceConfig = {
@ -146,8 +146,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/system-config-hera/bin/switch-to-configuration switch
/run/wrappers/bin/sudo -u ${user} /var/cache/gc-links/home-config-hera/default/activate
nixos-rebuild switch
# /run/wrappers/bin/sudo -u ${user} /var/cache/gc-links/home-config-hera/default/activate
'';
};
};