Convert hard-coded parameters to nix module
options and run nixpkgs-fmt
This commit is contained in:
parent
f74ffebc23
commit
b5b6f421ed
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
description = "devs & ops environment for nix'ing with triton";
|
description = "devshell nix module for triton DevOps shell environment";
|
||||||
|
|
||||||
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";
|
||||||
|
@ -12,46 +12,69 @@
|
||||||
"x86_64-darwin"
|
"x86_64-darwin"
|
||||||
"x86_64-linux"
|
"x86_64-linux"
|
||||||
]
|
]
|
||||||
(
|
(
|
||||||
system:
|
system:
|
||||||
let
|
let
|
||||||
pkgs = import nixpkgs {
|
pkgs = import nixpkgs {
|
||||||
inherit system;
|
inherit system;
|
||||||
|
|
||||||
overlays = [
|
overlays = [
|
||||||
devshell.overlay
|
devshell.overlay
|
||||||
(import ./overlay.nix)
|
(import ./overlay.nix)
|
||||||
];
|
];
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
devshellModules.tritonshell = { config, lib, ... }: {
|
|
||||||
options.environment = {
|
|
||||||
enable = lib.mkEnableOption "triton DevOps shell environment";
|
|
||||||
};
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
devshellModules.tritonshell = { config, lib, ... }:
|
||||||
|
with lib;
|
||||||
|
{
|
||||||
|
options = {
|
||||||
|
environment = {
|
||||||
|
enable = mkEnableOption "triton DevOps shell environment";
|
||||||
|
cnsBaseDomain = mkOption {
|
||||||
|
description = "Base domain for generated CNS domain records";
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = "greenbaum.zone";
|
||||||
|
};
|
||||||
|
dataCenters = mkOption {
|
||||||
|
description = "List of available triton data centers";
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [ "cgn-1" "lev-1" ];
|
||||||
|
};
|
||||||
|
mantaDomain = mkOption {
|
||||||
|
description = "Domain for manta object storage service";
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = "eu-central.manta.greenbaum.cloud";
|
||||||
|
};
|
||||||
|
tritonApiDomain = mkOption {
|
||||||
|
description = "Domain for triton API";
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = "api.greenbaum.cloud";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
config =
|
config =
|
||||||
lib.mkIf config.environment.enable (import ./tritonshell.nix { inherit devshell pkgs self system; });
|
lib.mkIf config.environment.enable
|
||||||
};
|
(import ./tritonshell.nix { inherit config devshell pkgs self system; });
|
||||||
# Internal utility package with shell function and env vars helper.
|
};
|
||||||
# These get source'd in devshell.bash.extra when starting tritonshell
|
# Internal utility package with shell function and env vars helper.
|
||||||
packages = {
|
# These get source'd in devshell.bash.extra when starting tritonshell
|
||||||
triton-utils = import ./pkgs/triton-utils.nix { inherit pkgs; };
|
packages = {
|
||||||
triton-docker-env =
|
triton-utils = import ./pkgs/triton-utils.nix { inherit pkgs; };
|
||||||
let
|
triton-docker-env =
|
||||||
# CUSTOMIZE:
|
#let
|
||||||
# variables used to set triton env vars in tritonshell
|
# # CUSTOMIZE:
|
||||||
# adjust to suit your Triton Data Center setup
|
# # variables used to set triton env vars in tritonshell
|
||||||
# take a look at ./pkgs/triton-docker-env-shell.nix to see how these get used
|
# # adjust to suit your Triton Data Center setup
|
||||||
cnsBaseDomain = "greenbaum.zone";
|
# # take a look at ./pkgs/triton-docker-env-shell.nix to see how these get used
|
||||||
dataCenters = [ "cgn-1" "lev-1" ];
|
# cnsBaseDomain = "greenbaum.zone";
|
||||||
mantaDomain = "eu-central.manta.greenbaum.cloud";
|
# dataCenters = [ "cgn-1" "lev-1" ];
|
||||||
tritonApiDomain = "api.greenbaum.cloud";
|
# mantaDomain = "eu-central.manta.greenbaum.cloud";
|
||||||
in
|
# tritonApiDomain = "api.greenbaum.cloud";
|
||||||
import ./pkgs/triton-docker-env.nix {
|
#in
|
||||||
inherit pkgs cnsBaseDomain dataCenters mantaDomain tritonApiDomain;
|
import ./pkgs/triton-docker-env.nix { inherit pkgs; };
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
}
|
);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,36 @@
|
||||||
{ pkgs, cnsBaseDomain, dataCenters, mantaDomain, tritonApiDomain, ... }:
|
{ pkgs, ... }:
|
||||||
with pkgs.nodePackages;
|
with pkgs.nodePackages;
|
||||||
''
|
''
|
||||||
export PATH="${triton}/bin:${json}/bin:$PATH"
|
# Script to set the docker, triton, manta and CNS env vars for the current
|
||||||
# script to set the docker, triton, manta and CNS env vars for the current
|
|
||||||
# triton profile
|
# triton profile
|
||||||
|
# Docs: https://docs.greenbaum.cloud/en/devops/triton-cli.html
|
||||||
|
# triton CLI source: https://github.com/tritonDataCenter/node-triton
|
||||||
|
cnsBaseDomain=$TRITONSHELL_CNS_BASE_DOMAIN
|
||||||
|
dataCenters=$TRITONSHELL_DATA_CENTERS
|
||||||
|
mantaDomain=$TRITONSHELL_MANTA_DOMAIN
|
||||||
|
tritonApiDomain=$TRITONSHELL_TRITON_API_DOMAIN
|
||||||
|
|
||||||
# set triton and docker host environment variables
|
# Set triton and docker host environment variables
|
||||||
eval "$(triton env)"
|
eval "$(${triton}/bin/triton env)"
|
||||||
|
|
||||||
# get the user's UUID
|
# Get the user's UUID
|
||||||
triton_account_uuid="$(triton account get --json | json id)"
|
triton_account_uuid="$(${triton}/bin/triton account get --json | ${json}/bin/json id)"
|
||||||
|
|
||||||
# set the CNS (container name service) base for auto-generated DNS records
|
# Set the CNS (container name service) base domain for auto-generated DNS
|
||||||
# in public and private networks
|
# records in public and private networks
|
||||||
# note, this makes assumptions that only work if you configured the nix
|
# Note: the defaults are configured to work with our data centers, adjust the
|
||||||
# variables in flake.nix "CUSTOMIZE" section according to your Triton Data
|
# nix module options like config.environment.cnsBaseDomain in your devshell
|
||||||
# Center setup
|
# if you'd like to use tritonshell with your own, self-hosted TritonDataCenter
|
||||||
for dc in ${pkgs.lib.concatStringsSep " " dataCenters}; do
|
for dc in "''${dataCenters[@]}"; do
|
||||||
if env | grep -q -E "SDC_URL=https://''${dc}.${tritonApiDomain}"; then
|
if env | grep -q -E "SDC_URL=https://''${dc}.''${tritonApiDomain}"; then
|
||||||
export \
|
export \
|
||||||
TRITON_CNS_SEARCH_DOMAIN_PUBLIC="''${triton_account_uuid}.''${dc}.${cnsBaseDomain}" \
|
TRITON_CNS_SEARCH_DOMAIN_PUBLIC="''${triton_account_uuid}.''${dc}.''${cnsBaseDomain}" \
|
||||||
TRITON_CNS_SEARCH_DOMAIN_PRIVATE="''${triton_account_uuid}.''${dc}.int.${cnsBaseDomain}" \
|
TRITON_CNS_SEARCH_DOMAIN_PRIVATE="''${triton_account_uuid}.''${dc}.int.''${cnsBaseDomain}" \
|
||||||
TRITON_DC=''$dc
|
TRITON_DC=''$dc
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
export MANTA_URL=https://${mantaDomain}
|
export MANTA_URL=https://''${mantaDomain}
|
||||||
export MANTA_USER=$SDC_ACCOUNT
|
export MANTA_USER=$SDC_ACCOUNT
|
||||||
export MANTA_KEY_ID=$SDC_KEY_ID
|
export MANTA_KEY_ID=$SDC_KEY_ID
|
||||||
''
|
''
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
{ pkgs, cnsBaseDomain, dataCenters, mantaDomain, tritonApiDomain, ... }:
|
{ pkgs, ... }:
|
||||||
(pkgs.writeShellScriptBin "triton-docker-env.sh" (import ./triton-docker-env-shell.nix { inherit pkgs cnsBaseDomain dataCenters mantaDomain tritonApiDomain; }))
|
(pkgs.writeShellScriptBin "triton-docker-env.sh" (import ./triton-docker-env-shell.nix { inherit pkgs; }))
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
{ devshell, pkgs, self, system, ... }:
|
{ config, devshell, pkgs, self, system, ... }:
|
||||||
|
let
|
||||||
|
tritonConfig = config.environment;
|
||||||
|
cnsBaseDomain = tritonConfig.cnsBaseDomain;
|
||||||
|
dataCenters = tritonConfig.dataCenters;
|
||||||
|
mantaDomain = tritonConfig.mantaDomain;
|
||||||
|
tritonApiDomain = tritonConfig.tritonApiDomain;
|
||||||
|
in
|
||||||
{
|
{
|
||||||
# devshell docs: https://numtide.github.io/devshell/modules_schema.html
|
# devshell docs: https://numtide.github.io/devshell/modules_schema.html
|
||||||
name = "tritonshell";
|
name = "tritonshell";
|
||||||
|
@ -60,8 +67,9 @@
|
||||||
self.packages.${system}.triton-utils
|
self.packages.${system}.triton-utils
|
||||||
self.packages.${system}.triton-docker-env
|
self.packages.${system}.triton-docker-env
|
||||||
# useful for working with JSON data
|
# useful for working with JSON data
|
||||||
jq
|
|
||||||
bunyan-rs
|
bunyan-rs
|
||||||
|
jq
|
||||||
|
nodePackages.json
|
||||||
];
|
];
|
||||||
|
|
||||||
env = [
|
env = [
|
||||||
|
@ -87,6 +95,11 @@
|
||||||
|
|
||||||
bash = {
|
bash = {
|
||||||
extra = ''
|
extra = ''
|
||||||
|
export \
|
||||||
|
TRITONSHELL_CNS_BASE_DOMAIN=${cnsBaseDomain} \
|
||||||
|
TRITONSHELL_DATA_CENTERS=(${pkgs.lib.concatStringsSep " " dataCenters}) \
|
||||||
|
TRITONSHELL_MANTA_DOMAIN=${mantaDomain} \
|
||||||
|
TRITONSHELL_TRITON_API_DOMAIN=${tritonApiDomain}
|
||||||
if [ -z "$TRITON_DONT_SOURCE_PROFILE" ]; then
|
if [ -z "$TRITON_DONT_SOURCE_PROFILE" ]; then
|
||||||
source ${self.packages.${system}.triton-docker-env}/bin/triton-docker-env.sh
|
source ${self.packages.${system}.triton-docker-env}/bin/triton-docker-env.sh
|
||||||
source ${self.packages.${system}.triton-utils}/bin/ttp.sh
|
source ${self.packages.${system}.triton-utils}/bin/ttp.sh
|
||||||
|
|
Loading…
Reference in a new issue