Refactor, init template
This commit is contained in:
parent
6c51d36c90
commit
bf103953de
20
README.md
20
README.md
|
@ -1,2 +1,22 @@
|
||||||
# tritonshell
|
# tritonshell
|
||||||
### a nix devshell for triton
|
### a nix devshell for triton
|
||||||
|
|
||||||
|
0. If you're already on NixOS jump to 2.
|
||||||
|
1. [Install nix](https://nixos.org/download.html)
|
||||||
|
|
||||||
|
1. Now, make sure you're ready to nix with flakes, this should give you some output:
|
||||||
|
```
|
||||||
|
nix flake --help
|
||||||
|
```
|
||||||
|
2. Otherwise, proceed to enable flakes (still an experimental feature in `nix`):
|
||||||
|
https://nixos.wiki/wiki/Flakes#Installing_flakes
|
||||||
|
|
||||||
|
2. Get this nix flake template:
|
||||||
|
```
|
||||||
|
nix flake new 'git+https://git.greenbaum.cloud/greenbaum.cloud/tritonshell'
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Ready to go:
|
||||||
|
```
|
||||||
|
nix develop
|
||||||
|
```
|
||||||
|
|
20
flake.lock
20
flake.lock
|
@ -2,11 +2,11 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"devshell": {
|
"devshell": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1642188268,
|
"lastModified": 1643393796,
|
||||||
"narHash": "sha256-DNz4xScpXIn7rSDohdayBpPR9H9OWCMDOgTYegX081k=",
|
"narHash": "sha256-+wb2OFWJjXUZw3HQezACc9Lj/5uuhNpUtrjDiIYw8H4=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "devshell",
|
"repo": "devshell",
|
||||||
"rev": "696acc29668b644df1740b69e1601119bf6da83b",
|
"rev": "fff3dc6e4538f6df85ee3027f13cc7730b23f61d",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -32,11 +32,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1642768189,
|
"lastModified": 1643630271,
|
||||||
"narHash": "sha256-XuUHXFzJWuSDo7dzpjTbHrjk37lAdTyk05sypXsqv1g=",
|
"narHash": "sha256-E49xk1KCW+0211Lnmhdt5WvVzUI3Se8Y74N6pUkraPU=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "e31e42dfdee3922a618b37c6d5f55603c24d86a0",
|
"rev": "17f073ee6b61d2afcd2a3ce5c4e360436f68bef4",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -64,16 +64,16 @@
|
||||||
},
|
},
|
||||||
"nixpkgsUnstable": {
|
"nixpkgsUnstable": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1643000262,
|
"lastModified": 1643347846,
|
||||||
"narHash": "sha256-8hrbufiCcZgicU8UvHaRkruYuzM8z3lJvQkSh9ezMEg=",
|
"narHash": "sha256-O0tyXF//ppRpe9yT1Uu5n34yI2MWDyY6ZiJ4Qn5zIkE=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "cc68710784ffe0ee035ee7b726656c44566cac94",
|
"rev": "5bb20f9dc70e9ee16e21cc404b6508654931ce41",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"ref": "nixpkgs-unstable",
|
"ref": "nixos-unstable",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
|
|
118
flake.nix
118
flake.nix
|
@ -1,34 +1,19 @@
|
||||||
{
|
{
|
||||||
description = "Development environment for nix'ing with triton";
|
description = "devs & ops environment for nix'ing with triton";
|
||||||
|
|
||||||
inputs.devshell.url = "github:numtide/devshell";
|
inputs.devshell.url = "github:numtide/devshell";
|
||||||
inputs.flake-utils.url = "github:numtide/flake-utils";
|
inputs.flake-utils.url = "github:numtide/flake-utils";
|
||||||
inputs.nixpkgs.url = "github:nixos/nixpkgs/release-21.11";
|
inputs.nixpkgs.url = "github:nixos/nixpkgs/release-21.11";
|
||||||
inputs.nixpkgsUnstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
inputs.nixpkgsUnstable.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||||
inputs.nixpkgs20-09.url = "github:nixos/nixpkgs/release-20.09";
|
inputs.nixpkgs20-09.url = "github:nixos/nixpkgs/release-20.09";
|
||||||
|
|
||||||
outputs = { self, flake-utils, devshell, nixpkgs, nixpkgsUnstable, nixpkgs20-09 }:
|
outputs = { self, flake-utils, devshell, nixpkgs, nixpkgsUnstable, nixpkgs20-09 }:
|
||||||
flake-utils.lib.eachDefaultSystem (system: {
|
flake-utils.lib.eachDefaultSystem (system: {
|
||||||
packages.triton-utils =
|
|
||||||
let
|
|
||||||
pkgs = import nixpkgs {
|
|
||||||
inherit system;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
pkgs.stdenv.mkDerivation {
|
|
||||||
pname = "triton-utils";
|
|
||||||
version = "0.0.1";
|
|
||||||
src = pkgs.lib.cleanSource ./.;
|
|
||||||
|
|
||||||
installPhase = ''
|
# Internal utility package with shell function and env vars helper.
|
||||||
mkdir -p $out/bin $out/share/certs
|
# These get source'd in devshell.bash.extra when starting tritonshell
|
||||||
cd ./utils
|
packages.triton-utils = import ./pkgs/triton-utils.nix { inherit nixpkgs; inherit system; };
|
||||||
cp ./cacert-2021-10-26.pem $out/share/certs
|
|
||||||
cp ./triton-docker.env.sh $out/bin
|
|
||||||
cp ./ttp.sh $out/bin
|
|
||||||
cp ./unset-env.sh $out/bin
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
devShell =
|
devShell =
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
|
@ -46,89 +31,20 @@
|
||||||
|
|
||||||
overlays = [ devshell.overlay ];
|
overlays = [ devshell.overlay ];
|
||||||
};
|
};
|
||||||
in
|
|
||||||
pkgs.devshell.mkShell {
|
|
||||||
name = "tritonshell";
|
|
||||||
|
|
||||||
devshell.interactive = {
|
# HINT: add your extra pkgs here,
|
||||||
PS1_util = pkgs.lib.noDepEntry ''
|
# they'll get appended to devshell.packages in ./tritonshell.nix
|
||||||
if [[ -n "''${PRJ_ROOT:-}" ]]; then
|
extraDevshellPkgs = [
|
||||||
# Print the path relative to $PRJ_ROOT
|
pkgsUnstable.consul
|
||||||
rel_root() {
|
pkgsUnstable.nomad
|
||||||
local path
|
|
||||||
path=$(${pkgs.coreutils}/bin/realpath --relative-to "$PRJ_ROOT" "$PWD")
|
|
||||||
if [[ $path != . ]]; then
|
|
||||||
echo " $path "
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
else
|
|
||||||
# If PRJ_ROOT is unset, print only the current directory name
|
|
||||||
rel_root() {
|
|
||||||
echo " \W "
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
PS1.text = ''
|
|
||||||
PS1='\[\033[38;5;202m\][$TRITON_PROFILE@tritonshell]$(rel_root)\$ \[\033[0m\]'
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
commands = [
|
|
||||||
{
|
|
||||||
package = pkgs.devshell.cli;
|
|
||||||
help = "Per project developer environments";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
package = pkgsUnstable.nodePackages.triton;
|
|
||||||
category = "triton & manta tools";
|
|
||||||
name = "triton";
|
|
||||||
help = "Triton DC CLI (https://docs.joyent.com/public-cloud/api/triton-cli)";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
package = pkgsUnstable.nodePackages.manta;
|
|
||||||
category = "triton & manta tools";
|
|
||||||
name = "manta";
|
|
||||||
help = "Manta CLI (https://apidocs.joyent.com/manta/index.html#cli)";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
devshell.packages = [
|
|
||||||
pkgs.bash-completion
|
|
||||||
# use docker-compose version 1.26.2 for best triton API compatibility
|
|
||||||
pkgs20-09.docker-compose
|
|
||||||
# used in ./utils/triton-docker.env.sh
|
|
||||||
pkgs.nodePackages.json
|
|
||||||
self.packages.${system}.triton-utils
|
|
||||||
pkgsUnstable.terraform
|
pkgsUnstable.terraform
|
||||||
pkgs.python39Packages.ansible
|
pkgsUnstable.vault
|
||||||
];
|
];
|
||||||
|
|
||||||
env = [
|
in
|
||||||
# workaround for TLS certs bug in docker-compose, CERTIFICATE_VERIFY_FAILED
|
import ./tritonshell.nix { inherit extraDevshellPkgs devshell pkgs pkgsUnstable pkgs20-09 self system; };
|
||||||
# see: https://github.com/joyent/triton-docker-cli/issues/17
|
}) // {
|
||||||
{
|
# merge this into the attr set above
|
||||||
name = "CURL_CA_BUNDLE";
|
defaultTemplate.description = "nix flake new 'git+https://git.greenbaum.cloud/greenbaum.cloud/tritonshell'";
|
||||||
value = "${self.packages.${system}.triton-utils}/share/certs/cacert-2021-10-26.pem";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "NOMAD_ADDR";
|
|
||||||
value = "https://nomad.service.consul:4646";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "VAULT_ADDR";
|
|
||||||
value = "https://nomad.service.consul:8200";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
bash = {
|
|
||||||
extra = ''
|
|
||||||
source ${self.packages.${system}.triton-utils}/bin/triton-docker.env.sh
|
|
||||||
source ${self.packages.${system}.triton-utils}/bin/ttp.sh
|
|
||||||
if [ "$(uname)" == "Darwin" ]; then
|
|
||||||
source $DEVSHELL_DIR/share/bash-completion/bash_completion
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
20
pkgs/triton-utils.nix
Normal file
20
pkgs/triton-utils.nix
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{ nixpkgs, system, ... }:
|
||||||
|
let
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
pkgs.stdenv.mkDerivation {
|
||||||
|
pname = "triton-utils";
|
||||||
|
version = "0.0.1";
|
||||||
|
src = pkgs.lib.cleanSource ./.;
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out/bin $out/share/certs
|
||||||
|
cd ./utils
|
||||||
|
cp ./cacert-2021-10-26.pem $out/share/certs
|
||||||
|
cp ./triton-docker.env.sh $out/bin
|
||||||
|
cp ./ttp.sh $out/bin
|
||||||
|
cp ./unset-env.sh $out/bin
|
||||||
|
'';
|
||||||
|
}
|
89
tritonshell.nix
Normal file
89
tritonshell.nix
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
{ extraDevshellPkgs, devshell, pkgs, pkgsUnstable, pkgs20-09, self, system, ... }:
|
||||||
|
pkgs.devshell.mkShell {
|
||||||
|
# devshell docs: https://numtide.github.io/devshell/modules_schema.html
|
||||||
|
name = "tritonshell";
|
||||||
|
|
||||||
|
devshell.interactive = {
|
||||||
|
PS1_util = pkgs.lib.noDepEntry ''
|
||||||
|
if [[ -n "''${PRJ_ROOT:-}" ]]; then
|
||||||
|
# Print the path relative to $PRJ_ROOT
|
||||||
|
rel_root() {
|
||||||
|
local path
|
||||||
|
path=$(${pkgs.coreutils}/bin/realpath --relative-to "$PRJ_ROOT" "$PWD")
|
||||||
|
if [[ $path != . ]]; then
|
||||||
|
echo " $path "
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
else
|
||||||
|
# If PRJ_ROOT is unset, print only the current directory name
|
||||||
|
rel_root() {
|
||||||
|
echo " \W "
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
PS1.text = ''
|
||||||
|
PS1='\[\033[38;5;202m\][$TRITON_PROFILE@tritonshell]$(rel_root)\$ \[\033[0m\]'
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
commands = [
|
||||||
|
{
|
||||||
|
package = pkgs.devshell.cli;
|
||||||
|
help = "Per project developer environments";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
package = pkgsUnstable.nodePackages.triton;
|
||||||
|
category = "triton & manta tools";
|
||||||
|
name = "triton";
|
||||||
|
help = "Triton DC CLI (https://docs.joyent.com/public-cloud/api/triton-cli)";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
package = pkgsUnstable.nodePackages.manta;
|
||||||
|
category = "triton & manta tools";
|
||||||
|
name = "manta";
|
||||||
|
help = "Manta CLIs (https://apidocs.joyent.com/manta/index.html#cli)";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
devshell.packages = [
|
||||||
|
pkgs.bash-completion
|
||||||
|
# use docker-compose version 1.26.2 for best triton API compatibility
|
||||||
|
pkgs20-09.docker-compose
|
||||||
|
# used in ./utils/triton-docker.env.sh
|
||||||
|
pkgs.nodePackages.json
|
||||||
|
pkgs.bunyan-rs
|
||||||
|
self.packages.${system}.triton-utils
|
||||||
|
pkgs.ansible
|
||||||
|
] ++ extraDevshellPkgs;
|
||||||
|
|
||||||
|
env = [
|
||||||
|
# workaround for TLS certs bug in docker-compose, CERTIFICATE_VERIFY_FAILED
|
||||||
|
# see: https://github.com/joyent/triton-docker-cli/issues/17
|
||||||
|
{
|
||||||
|
name = "CURL_CA_BUNDLE";
|
||||||
|
value = "${self.packages.${system}.triton-utils}/share/certs/cacert-2021-10-26.pem";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "CONSUL_HTTP_ADDR";
|
||||||
|
value = "http://consul.service.consul:8500";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "NOMAD_ADDR";
|
||||||
|
value = "https://nomad.service.consul:4646";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "VAULT_ADDR";
|
||||||
|
value = "https://nomad.service.consul:8200";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
bash = {
|
||||||
|
extra = ''
|
||||||
|
source ${self.packages.${system}.triton-utils}/bin/triton-docker.env.sh
|
||||||
|
source ${self.packages.${system}.triton-utils}/bin/ttp.sh
|
||||||
|
if [ "$(uname)" == "Darwin" ]; then
|
||||||
|
source $DEVSHELL_DIR/share/bash-completion/bash_completion
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue