Skip to content

Instantly share code, notes, and snippets.

@brainrake
Last active July 15, 2020 06:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brainrake/c895b7569de0c9966c3ab87d15d133f3 to your computer and use it in GitHub Desktop.
Save brainrake/c895b7569de0c9966c3ab87d15d133f3 to your computer and use it in GitHub Desktop.
nix-shell shebang haskell turtle nixos deploy script
#! /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