1- #! /usr/bin/env bash
1+ #! /usr/bin/env nix-shell
2+ #! nix-shell -i bash -p nixopsUnstable which jq nix openssl openssh
3+ #! nix-shell -p "(import ./nixpkgs.nix)"
24
35# A NixOps Wrapper for Git Projects
46# ---------------------------------
57#
6- # Repo : https://github.com/grafted-in/nixops-manager
8+ # Modified from repo : https://github.com/grafted-in/nixops-manager
79#
810# This tool is a simple wrapper around NixOps. The goal is to make it easier to use NixOps when you
911# want to share your deployment state between members of a team.
1012#
1113# To achieve this, this wrapper gives every deployment as a separate state file which is placed
12- # in the same directory as this script. The files have the `.nixops` extension.
14+ # in a sub- directory of this script. The files have the `.nixops` extension.
1315#
1416# You are expected to keep these files in version control. It's also *highly* recommended that you
1517# use a tool like git-crypt to keep them encrypted with this entry in .gitattributes:
1618#
1719# *.nixops binary filter=git-crypt diff=git-crypt
1820#
19- # This tool also enforces a per-repository version of Nixpkgs via a `nixpkgs-version.sh` file in the
20- # same directory as the script. This ensures that all users have a consistent version of NixOps and
21- # deploy a consistent set of packages to servers.
22- #
2321# Most commands work identically to NixOps. However, instead of specifying deployments with
2422# the `--deployment/-d` flag, you select a deployment in the first argument. In other words, instead
2523# of the normal NixOps usage of
3028#
3129# ./manage stage deploy --check # Manage script usage.
3230#
33- # This assume there is a file ./stage.nixops where this state is being stored.
31+ # This assume there is a file ./stage/stage .nixops where this state is being stored.
3432#
3533# Use `./manage --help` to see normal NixOps help.
3634# Use `./manage {deployment} .shell` to open a Nix shell where the environment is set up to use
3735# `nixops` directly with the same behavior as running `./manage` commands.
3836
3937set -e
4038
41- # Check for Nix tools.
42- command -v nix-shell > /dev/null 2>&1 || {
43- nix_profile=" $HOME /.nix-profile/etc/profile.d/nix.sh"
44- if [ -e " $nix_profile " ]; then
45- source " $nix_profile "
46- else
47- >&2 echo " Failed to find 'nix-shell' on PATH or a Nix profile to load. Have you installed Nix?"
48- exit 1
49- fi
50- }
51-
5239here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
53- repo_root=$( cd " $here " && git rev-parse --show-toplevel) # Use Git to find repo root.
5440
5541deployment="$1"
5642command="$2"
57- state_file=" $here /${deployment} .nixops"
58-
59- source " $here /nixpkgs-version.sh"
43+ state_file="$here/${deployment}/${deployment}.nixops"
6044
6145function colon(){
6246 echo ${1:+${1}:}
6347}
64- export NIX_PATH=nixpkgs=" $( colon $nixpkgs_cache ) $( colon $nixpkgs_snapshot ) $repo_root " :.
65- export NIXOPS_STATE=" $state_file "
66- export NIXOPS_DEPLOYMENT=" $deployment "
48+ export NIX_PATH=nixpkgs=$(nix-instantiate --eval ./nixpkgs.nix | tr -d '"' ):./${deployment}
6749
68- withNixops=" nix-shell -p $nixops_version --run"
6950
70- # Arg list trick:
71- # https://stackoverflow.com/questions/3104209
72- # ARGS=$(printf "%q"" " "$@")
51+ export NIXOPS_STATE="$state_file"
52+ export NIXOPS_DEPLOYMENT="$deployment"
53+ export nixops_version="nixopsUnstable"
7354
7455if [[ $deployment == --* ]]; then
75- ARGS=$( printf " %q" " " " $@ " )
76- $withNixops " nixops $ARGS "
56+ nixops "$@"
7757 exit $?
7858elif [ "$command" == ".shell" ]; then
79- nix-shell -p " $nixops_version "
59+ nix-shell -p "$nixops_version" --command "echo You may now run commands for deployment:$deploymnet with \\'nixops\\' ; return "
8060elif [ ! -e "$state_file" ] && [ "$command" != "create" ]; then
8161 >&2 echo "You're trying to use a deployment that doesn't exist yet. Try running $0 $deployment create"
8262 exit 1
8363elif [ -e "$state_file" ] && [ "$command" == "create" ]; then
8464 >&2 echo "You're trying to create a deployment that already exists."
8565 exit 1
8666else
87- ARGS=$( printf " %q" " " " ${@: 2} " )
88- $withNixops " nixops $ARGS "
89- fi
67+ nixops "${@:2}"
68+ fi
0 commit comments