Convert hard-coded parameters to nix module

options

and run nixpkgs-fmt
This commit is contained in:
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.devshell.url = "github:numtide/devshell";
inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.flake-utils.url = "github:numtide/flake-utils";
@ -25,32 +25,55 @@
}; };
in in
{ {
devshellModules.tritonshell = { config, lib, ... }: { devshellModules.tritonshell = { config, lib, ... }:
options.environment = { with lib;
enable = lib.mkEnableOption "triton DevOps shell environment"; {
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. # Internal utility package with shell function and env vars helper.
# These get source'd in devshell.bash.extra when starting tritonshell # These get source'd in devshell.bash.extra when starting tritonshell
packages = { packages = {
triton-utils = import ./pkgs/triton-utils.nix { inherit pkgs; }; triton-utils = import ./pkgs/triton-utils.nix { inherit pkgs; };
triton-docker-env = triton-docker-env =
let #let
# CUSTOMIZE: # # CUSTOMIZE:
# variables used to set triton env vars in tritonshell # # variables used to set triton env vars in tritonshell
# adjust to suit your Triton Data Center setup # # adjust to suit your Triton Data Center setup
# take a look at ./pkgs/triton-docker-env-shell.nix to see how these get used # # take a look at ./pkgs/triton-docker-env-shell.nix to see how these get used
cnsBaseDomain = "greenbaum.zone"; # cnsBaseDomain = "greenbaum.zone";
dataCenters = [ "cgn-1" "lev-1" ]; # dataCenters = [ "cgn-1" "lev-1" ];
mantaDomain = "eu-central.manta.greenbaum.cloud"; # mantaDomain = "eu-central.manta.greenbaum.cloud";
tritonApiDomain = "api.greenbaum.cloud"; # tritonApiDomain = "api.greenbaum.cloud";
in #in
import ./pkgs/triton-docker-env.nix { import ./pkgs/triton-docker-env.nix { inherit pkgs; };
inherit pkgs cnsBaseDomain dataCenters mantaDomain tritonApiDomain;
};
}; };
} }
); );

View file

@ -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
'' ''

View file

@ -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; }))

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 # 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