Convert hard-coded parameters to nix module

options

and run nixpkgs-fmt
main
jhonas 2022-10-12 13:01:33 +02:00
parent f74ffebc23
commit b5b6f421ed
Signed by: teutat3s
GPG Key ID: 924889A86D0B0FEB
4 changed files with 101 additions and 60 deletions

View File

@ -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.flake-utils.url = "github:numtide/flake-utils";
@ -12,46 +12,69 @@
"x86_64-darwin"
"x86_64-linux"
]
(
system:
let
pkgs = import nixpkgs {
inherit system;
(
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
devshell.overlay
(import ./overlay.nix)
];
};
in
{
devshellModules.tritonshell = { config, lib, ... }: {
options.environment = {
enable = lib.mkEnableOption "triton DevOps shell environment";
overlays = [
devshell.overlay
(import ./overlay.nix)
];
};
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 =
lib.mkIf config.environment.enable (import ./tritonshell.nix { inherit 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
packages = {
triton-utils = import ./pkgs/triton-utils.nix { inherit pkgs; };
triton-docker-env =
let
# CUSTOMIZE:
# variables used to set triton env vars in tritonshell
# adjust to suit your Triton Data Center setup
# take a look at ./pkgs/triton-docker-env-shell.nix to see how these get used
cnsBaseDomain = "greenbaum.zone";
dataCenters = [ "cgn-1" "lev-1" ];
mantaDomain = "eu-central.manta.greenbaum.cloud";
tritonApiDomain = "api.greenbaum.cloud";
in
import ./pkgs/triton-docker-env.nix {
inherit pkgs cnsBaseDomain dataCenters mantaDomain tritonApiDomain;
config =
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
packages = {
triton-utils = import ./pkgs/triton-utils.nix { inherit pkgs; };
triton-docker-env =
#let
# # CUSTOMIZE:
# # variables used to set triton env vars in tritonshell
# # adjust to suit your Triton Data Center setup
# # take a look at ./pkgs/triton-docker-env-shell.nix to see how these get used
# cnsBaseDomain = "greenbaum.zone";
# dataCenters = [ "cgn-1" "lev-1" ];
# mantaDomain = "eu-central.manta.greenbaum.cloud";
# tritonApiDomain = "api.greenbaum.cloud";
#in
import ./pkgs/triton-docker-env.nix { inherit pkgs; };
};
};
}
);
}
);
}

View File

@ -1,31 +1,36 @@
{ pkgs, cnsBaseDomain, dataCenters, mantaDomain, tritonApiDomain, ... }:
{ pkgs, ... }:
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
# 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
eval "$(triton env)"
# Set triton and docker host environment variables
eval "$(${triton}/bin/triton env)"
# get the user's UUID
triton_account_uuid="$(triton account get --json | json id)"
# Get the user's UUID
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
# in public and private networks
# note, this makes assumptions that only work if you configured the nix
# variables in flake.nix "CUSTOMIZE" section according to your Triton Data
# Center setup
for dc in ${pkgs.lib.concatStringsSep " " dataCenters}; do
if env | grep -q -E "SDC_URL=https://''${dc}.${tritonApiDomain}"; then
# Set the CNS (container name service) base domain for auto-generated DNS
# records in public and private networks
# Note: the defaults are configured to work with our data centers, adjust the
# nix module options like config.environment.cnsBaseDomain in your devshell
# if you'd like to use tritonshell with your own, self-hosted TritonDataCenter
for dc in "''${dataCenters[@]}"; do
if env | grep -q -E "SDC_URL=https://''${dc}.''${tritonApiDomain}"; then
export \
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_PUBLIC="''${triton_account_uuid}.''${dc}.''${cnsBaseDomain}" \
TRITON_CNS_SEARCH_DOMAIN_PRIVATE="''${triton_account_uuid}.''${dc}.int.''${cnsBaseDomain}" \
TRITON_DC=''$dc
fi
done
export MANTA_URL=https://${mantaDomain}
export MANTA_URL=https://''${mantaDomain}
export MANTA_USER=$SDC_ACCOUNT
export MANTA_KEY_ID=$SDC_KEY_ID
''

View File

@ -1,2 +1,2 @@
{ pkgs, cnsBaseDomain, dataCenters, mantaDomain, tritonApiDomain, ... }:
(pkgs.writeShellScriptBin "triton-docker-env.sh" (import ./triton-docker-env-shell.nix { inherit pkgs cnsBaseDomain dataCenters mantaDomain tritonApiDomain; }))
{ pkgs, ... }:
(pkgs.writeShellScriptBin "triton-docker-env.sh" (import ./triton-docker-env-shell.nix { inherit pkgs; }))

View File

@ -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
name = "tritonshell";
@ -60,8 +67,9 @@
self.packages.${system}.triton-utils
self.packages.${system}.triton-docker-env
# useful for working with JSON data
jq
bunyan-rs
jq
nodePackages.json
];
env = [
@ -87,6 +95,11 @@
bash = {
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
source ${self.packages.${system}.triton-docker-env}/bin/triton-docker-env.sh
source ${self.packages.${system}.triton-utils}/bin/ttp.sh