Skip to content

Commit 580eb16

Browse files
committed
Simplify
1 parent 37ad887 commit 580eb16

File tree

6 files changed

+84
-75
lines changed

6 files changed

+84
-75
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ You'd run:
3535
./manage stage deploy --check # Manage script usage.
3636
```
3737

38-
This assume there is a file `./stage.nixops` where this state is being stored.
38+
This assume there is a file `./stage/stage.nixops` where this state is being stored.
3939

4040
Use `./manage --help` to see normal NixOps help.
4141
Use `./manage {deployment} .shell` to open a Nix shell where the environment is set up to use

manage

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
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
@@ -30,60 +28,41 @@
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

3937
set -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-
5239
here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
53-
repo_root=$(cd "$here" && git rev-parse --show-toplevel) # Use Git to find repo root.
5440

5541
deployment="$1"
5642
command="$2"
57-
state_file="$here/${deployment}.nixops"
58-
59-
source "$here/nixpkgs-version.sh"
43+
state_file="$here/${deployment}/${deployment}.nixops"
6044

6145
function 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

7455
if [[ $deployment == --* ]]; then
75-
ARGS=$(printf "%q"" " "$@")
76-
$withNixops "nixops $ARGS"
56+
nixops "$@"
7757
exit $?
7858
elif [ "$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 "
8060
elif [ ! -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
8363
elif [ -e "$state_file" ] && [ "$command" == "create" ]; then
8464
>&2 echo "You're trying to create a deployment that already exists."
8565
exit 1
8666
else
87-
ARGS=$(printf "%q"" " "${@:2}")
88-
$withNixops "nixops $ARGS"
89-
fi
67+
nixops "${@:2}"
68+
fi

nixpkgs-version.nix

Lines changed: 0 additions & 15 deletions
This file was deleted.

nixpkgs-version.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

nixpkgs.nix

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
# Import this instead of <nixpkgs> to get the repo-specific version of nixpkgs.
2-
3-
import ((import <nixpkgs> {}).fetchzip (import ./nixpkgs-version.nix))
1+
builtins.fetchTarball {
2+
name = "nixos-unstable-2018-09-12";
3+
url = https://github.com/johanot/nixpkgs/archive/b3905f0d224bc5c2da3572f7017f05a27df742cd.tar.gz;
4+
sha256 = "05jxiyagfgl7s061vz2xmalrrbaz95ymcxdv89j3s700hicyd8pf";
5+
}

top-level.nix

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
{ targetEnv ? "virtualbox" } :
3+
let
4+
region = "us-gov-west-1";
5+
zone = "us-gov-west-1a";
6+
accessKeyId = "default";
7+
machine =
8+
{ config, pkgs, resources, ... }:{
9+
imports =
10+
(if targetEnv == "ec2" then
11+
[<nixpkgs/nixos/modules/virtualisation/amazon-image.nix>] else []) ++
12+
[ <nixpkgs/nixos/modules/profiles/minimal.nix> ];
13+
deployment.targetEnv = targetEnv;
14+
deployment.ec2 = {
15+
keyPair = resources.ec2KeyPairs.my-key-pair;
16+
ebsInitialRootDiskSize = 30;
17+
ebsOptimized = true;
18+
associatePublicIpAddress = true;
19+
ami = "ami-bb7618da";
20+
inherit region zone accessKeyId;
21+
instanceType = "t3.large";
22+
};
23+
ec2.hvm = true;
24+
boot.initrd.postDeviceCommands= ''
25+
${pkgs.e2fsprogs}/sbin/e2fsck -fp /dev/disk/by-label/nixos
26+
${pkgs.e2fsprogs}/sbin/resize2fs /dev/disk/by-label/nixos
27+
'';
28+
29+
deployment.virtualbox.memorySize = 4096; # megabytes
30+
deployment.virtualbox.vcpu = 2; # number of cpus
31+
deployment.virtualbox.headless = true;
32+
33+
networking.extraHosts = "${config.networking.privateIPv4} api.kube";
34+
services.kubernetes = {
35+
easyCerts = true;
36+
addons.dashboard.enable = true;
37+
roles = ["master" "node"];
38+
apiserver = {
39+
securePort = 443;
40+
advertiseAddress = config.networking.privateIPv4;
41+
};
42+
masterAddress = "api.kube";
43+
};
44+
services.dockerRegistry.enable = true;
45+
environment.systemPackages = with pkgs; [
46+
kompose kubectl
47+
vim e2fsprogs
48+
];
49+
networking.firewall.allowedTCPPorts = [22 443 ];
50+
users.users.root.openssh.authorizedKeys = {
51+
keyFiles = [ ];
52+
};
53+
};
54+
in {
55+
kubemaster = machine;
56+
57+
network.description = "kubenixops";
58+
network.enableRollback = true;
59+
resources = if targetEnv == "ec2" then {
60+
ec2KeyPairs.my-key-pair = { inherit region accessKeyId; };
61+
}else {};
62+
63+
}

0 commit comments

Comments
 (0)