Last active
July 15, 2020 06:39
-
-
Save brainrake/c895b7569de0c9966c3ab87d15d133f3 to your computer and use it in GitHub Desktop.
nix-shell shebang haskell turtle nixos deploy script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env nix-shell | |
#! nix-shell --pure -i runghc -p rsync openssh "haskellPackages.ghcWithPackages (pkgs: [ pkgs.turtle ])" | |
{-# LANGUAGE OverloadedStrings #-} | |
import Turtle | |
import Prelude hiding (FilePath) | |
import qualified Data.Text as T | |
sshOpts :: [Text] | |
sshOpts = ["-o", "StrictHostKeyChecking=accept-new"] | |
rsync :: Text -> Text -> Shell Line | |
rsync host file = | |
inproc "rsync" | |
["-rzP", "-e", "ssh " <> T.unwords sshOpts, file, "root@" <> host <> ":/root/"] empty | |
ssh :: Text -> Text -> Shell Line | |
ssh host cmd = | |
inproc "ssh" | |
(sshOpts <> ["root@"<>host, cmd]) empty | |
deploy :: Text -> Shell Line | |
deploy host = | |
ssh host "nixos-rebuild build --show-trace && nixos-rebuild switch" | |
main = do | |
host <- options "Deploy application" $ argText "host" "host to deploy to" | |
stdout $ rsync host "eket-module.nix" | |
stdout $ deploy host |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment