Simplify update code
This commit is contained in:
parent
76eb0d78c2
commit
54209d661f
|
@ -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
|
||||
|
|
|
@ -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
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue