Simplify update code
This commit is contained in:
parent
76eb0d78c2
commit
54209d661f
|
@ -9,50 +9,31 @@
|
||||||
{-# LANGUAGE TupleSections #-}
|
{-# LANGUAGE TupleSections #-}
|
||||||
{-# LANGUAGE ViewPatterns #-}
|
{-# LANGUAGE ViewPatterns #-}
|
||||||
{-# LANGUAGE NoImplicitPrelude #-}
|
{-# 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.String.Interpolate
|
||||||
import Data.Text (stripPrefix)
|
import Data.Text (stripPrefix)
|
||||||
import Language.Haskell.TH.Syntax
|
import Language.Haskell.TH.Syntax
|
||||||
import Relude
|
import Relude
|
||||||
import Say
|
import Say
|
||||||
import Shh
|
import Shh
|
||||||
import System.Environment (getEnv, setEnv)
|
import System.Environment (getEnv)
|
||||||
|
|
||||||
load Absolute ["laminarc", "git", "nix"]
|
load Absolute ["laminarc", "git", "nix"]
|
||||||
|
|
||||||
repo = "git@hera.m-0.eu:nixos-config"
|
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 :: String
|
||||||
deployCommand = $$(bindCode (runIO $ getEnv "DEPLOY") liftTyped)
|
deployCommand = $$(bindCode (runIO $ getEnv "DEPLOY") liftTyped)
|
||||||
|
|
||||||
main = do
|
main = do
|
||||||
let process = fromMaybe "main" . (stripPrefix "refs/heads/" . toText =<<)
|
let process = fromMaybe "main" . (stripPrefix "refs/heads/" . toText =<<)
|
||||||
branch <- process <$> lookupEnv "BRANCH"
|
branch <- process <$> lookupEnv "BRANCH"
|
||||||
jobId <- getEnv "JOB"
|
|
||||||
runId <- getEnv "RUN"
|
|
||||||
git "clone" repo "."
|
git "clone" repo "."
|
||||||
git "checkout" (toString branch)
|
git "checkout" (toString branch)
|
||||||
setEnv "LAMINAR_REASON" [i|Building config branch #{branch} for all systems in #{jobId}:#{runId}|]
|
say "Running checks"
|
||||||
say [i|Starting builds of branch #{branch} for all systems.|]
|
nix "flake" "check"
|
||||||
concurrently_ (mapConcurrently_ (\x -> laminarc ["run", x, [i|BRANCH=#{branch}|]]) jobs) $ nix "flake" "check"
|
say "Checks succeeded"
|
||||||
say [i|Builds succeeded.|]
|
|
||||||
when (branch == "main") $ do
|
when (branch == "main") $ do
|
||||||
say [i|Deploying new config to localhost.|]
|
say [i|Deploying new config to localhost.|]
|
||||||
exe "/run/wrappers/bin/sudo" deployCommand
|
exe "/run/wrappers/bin/sudo" deployCommand
|
||||||
|
|
|
@ -135,7 +135,7 @@ in {
|
||||||
];
|
];
|
||||||
systemd.services = {
|
systemd.services = {
|
||||||
update-config = {
|
update-config = {
|
||||||
path = [pkgs.git pkgs.nix pkgs.openssh];
|
path = [pkgs.git pkgs.nix pkgs.openssh pkgs.nixos-rebuild];
|
||||||
restartIfChanged = false;
|
restartIfChanged = false;
|
||||||
unitConfig.X-StopOnRemoval = false;
|
unitConfig.X-StopOnRemoval = false;
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
|
@ -146,8 +146,8 @@ in {
|
||||||
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 pull --ff-only
|
||||||
/run/wrappers/bin/sudo -u ${user} git -C /etc/nixos submodule update --init
|
/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
|
nixos-rebuild switch
|
||||||
/run/wrappers/bin/sudo -u ${user} /var/cache/gc-links/home-config-hera/default/activate
|
# /run/wrappers/bin/sudo -u ${user} /var/cache/gc-links/home-config-hera/default/activate
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue