Skip to content

Commit

Permalink
Move deploy activation to script; add reboot logic
Browse files Browse the repository at this point in the history
  • Loading branch information
madeline-os committed Aug 3, 2022
1 parent ec10670 commit d91d680
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions lib/command/src/Obelisk/Command/Deploy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,8 @@ deployPush deployPath builders = do
proc sshPath $ sshOpts <>
[ "root@" <> host
, unwords
-- Note that we don't want to $(staticWhich "nix-env") here, because this is executing on a remote machine
[ "nix-env -p /nix/var/nix/profiles/system --set " <> outputPath
, "&&"
, "/nix/var/nix/profiles/system/bin/switch-to-configuration switch"
[ "bash -c"
, bashEscape (deployActivationScript outputPath)
]
]
isClean <- checkGitCleanStatus deployPath True
Expand All @@ -243,6 +241,27 @@ deployPush deployPath builders = do
let p = setEnvOverride (envMap <>) $ setDelegateCtlc True $ proc cmd args
callProcessAndLogOutput (Notice, Notice) p

-- | Bash command that will be run on the deployed machine to actually switch the NixOS configuration
-- This has some more involved logic than merely activating the right profile. It also determines
-- whether the kernel parameters have changed so that the deployed NixOS instance should be restarted.
deployActivationScript
:: String
-- ^ The out path of the configuration to activate
-> String
deployActivationScript outPath =
-- Note that we don't want to $(staticWhich "nix-env") here, because this is executing on a remote machine
[i|set -euxo pipefail
nix-env -p /nix/var/nix/profiles/system --set "${outPath}"
/nix/var/nix/profiles/system/bin/switch-to-configuration boot
booted="$(readlink /run/booted-system/{initrd,kernel,kernel-modules})"
built="$(readlink /nix/var/nix/profiles/system/{initrd,kernel,kernel-modules})"
if [ "$booted" = "$built" ]; then
/nix/var/nix/profiles/system/bin/switch-to-configuration switch
else
/run/current-system/sw/bin/shutdown -r +1
fi
|]

-- | Update the source thunk in the staging directory to the HEAD of the branch.
deployUpdate :: MonadObelisk m => FilePath -> m ()
deployUpdate deployPath = updateThunkToLatest (ThunkUpdateConfig Nothing (ThunkConfig Nothing)) (deployPath </> "src")
Expand Down

0 comments on commit d91d680

Please sign in to comment.