From aa428101e8efcbf41fbd7cd862bbf8056798709b Mon Sep 17 00:00:00 2001 From: jhonas Date: Fri, 7 Oct 2022 14:44:26 +0200 Subject: [PATCH 1/6] Test devshellModules --- template/flake.nix | 53 +++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/template/flake.nix b/template/flake.nix index 57ab9bc..222a5c5 100644 --- a/template/flake.nix +++ b/template/flake.nix @@ -19,27 +19,13 @@ }; in { - # 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; - }; + devshellModules.tritonshell = { config, lib, ... }: { + options.environment = { + enable = lib.mkEnableOption "environment"; + # TODO: add real config here }; - - devShells.default = + config = + # TODO: set some devshell config here, like add a new command let pkgs = import nixpkgs { inherit system; @@ -59,7 +45,30 @@ #hello ]; - in - import ./tritonshell.nix { inherit extraDevshellPkgs devshell pkgs self system; }; + in + lib.optionalAttrs config.environment.enable { + devShells.default = + (import ./tritonshell.nix { inherit extraDevshellPkgs 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; + }; + }; }); } From f74ffebc23306f5dec7380d71db2c8634e65acce Mon Sep 17 00:00:00 2001 From: jhonas Date: Tue, 11 Oct 2022 10:44:32 +0200 Subject: [PATCH 2/6] Fix infinite recursion with pkgs.devshell.mkShell --- template/flake.nix | 91 ++++++++++++++++------------------------ template/tritonshell.nix | 6 +-- 2 files changed, 40 insertions(+), 57 deletions(-) diff --git a/template/flake.nix b/template/flake.nix index 222a5c5..6a59439 100644 --- a/template/flake.nix +++ b/template/flake.nix @@ -12,63 +12,46 @@ "x86_64-darwin" "x86_64-linux" ] - (system: - let - pkgs = import nixpkgs { - inherit system; - }; - in - { + ( + system: + let + pkgs = import nixpkgs { + inherit system; + + overlays = [ + devshell.overlay + (import ./overlay.nix) + ]; + }; + in + { devshellModules.tritonshell = { config, lib, ... }: { options.environment = { - enable = lib.mkEnableOption "environment"; - # TODO: add real config here + enable = lib.mkEnableOption "triton DevOps shell environment"; }; + config = - # TODO: set some devshell config here, like add a new command - let - pkgs = import nixpkgs { - inherit system; - - overlays = [ - devshell.overlay - (import ./overlay.nix) - ]; - }; - - # HINT: add your extra devshell pkgs here, use any packages you want - # available in your devshell's PATH - # Use https://search.nixos.org/packages to find available packages - # in the unstable channel - # These get appended to devshell.packages in ./tritonshell.nix - extraDevshellPkgs = with pkgs; [ - #hello - ]; - - in - lib.optionalAttrs config.environment.enable { - devShells.default = - (import ./tritonshell.nix { inherit extraDevshellPkgs devshell pkgs self system; }); - }; + 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; }; - # 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; - }; - }; - }); + }; + } + ); } diff --git a/template/tritonshell.nix b/template/tritonshell.nix index f0f47dd..fd52f79 100644 --- a/template/tritonshell.nix +++ b/template/tritonshell.nix @@ -1,5 +1,5 @@ -{ extraDevshellPkgs, devshell, pkgs, self, system, ... }: -pkgs.devshell.mkShell { +{ devshell, pkgs, self, system, ... }: +{ # devshell docs: https://numtide.github.io/devshell/modules_schema.html name = "tritonshell"; @@ -62,7 +62,7 @@ pkgs.devshell.mkShell { # useful for working with JSON data jq bunyan-rs - ] ++ extraDevshellPkgs; + ]; env = [ # workaround for TLS certs bug in docker-compose, CERTIFICATE_VERIFY_FAILED From b5b6f421ed1a187ebb882b9fb1e28f6a4990d99f Mon Sep 17 00:00:00 2001 From: jhonas Date: Wed, 12 Oct 2022 13:01:33 +0200 Subject: [PATCH 3/6] Convert hard-coded parameters to nix module options and run nixpkgs-fmt --- template/flake.nix | 101 +++++++++++++--------- template/pkgs/triton-docker-env-shell.nix | 39 +++++---- template/pkgs/triton-docker-env.nix | 4 +- template/tritonshell.nix | 17 +++- 4 files changed, 101 insertions(+), 60 deletions(-) diff --git a/template/flake.nix b/template/flake.nix index 6a59439..c319f38 100644 --- a/template/flake.nix +++ b/template/flake.nix @@ -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; }; }; - }; - } - ); + } + ); } diff --git a/template/pkgs/triton-docker-env-shell.nix b/template/pkgs/triton-docker-env-shell.nix index 55e0dae..15e4b19 100644 --- a/template/pkgs/triton-docker-env-shell.nix +++ b/template/pkgs/triton-docker-env-shell.nix @@ -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 '' diff --git a/template/pkgs/triton-docker-env.nix b/template/pkgs/triton-docker-env.nix index 416e2c7..6cd8c8c 100644 --- a/template/pkgs/triton-docker-env.nix +++ b/template/pkgs/triton-docker-env.nix @@ -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; })) diff --git a/template/tritonshell.nix b/template/tritonshell.nix index fd52f79..47d647c 100644 --- a/template/tritonshell.nix +++ b/template/tritonshell.nix @@ -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 From 9f130ca346aab4938009f575b4bd673d67fb5cd4 Mon Sep 17 00:00:00 2001 From: jhonas Date: Wed, 12 Oct 2022 14:14:05 +0200 Subject: [PATCH 4/6] Move template/* one level up to better expose nix module options Create new template to show how to use this flake --- template/flake.lock => flake.lock | 6 +- flake.nix | 82 +++++++++++++-- template/overlay.nix => overlay.nix | 0 .../pkgs => pkgs}/triton-docker-env-shell.nix | 0 {template/pkgs => pkgs}/triton-docker-env.nix | 0 {template/pkgs => pkgs}/triton-utils.nix | 0 .../pkgs => pkgs}/utils/cacert-2022-07-19.pem | 0 {template/pkgs => pkgs}/utils/ttp.sh | 0 {template/pkgs => pkgs}/utils/unset-env.sh | 0 template/.envrc | 3 + template/.gitignore | 2 + template/flake.nix | 99 +++++-------------- template/tritonshell.nix => tritonshell.nix | 0 13 files changed, 109 insertions(+), 83 deletions(-) rename template/flake.lock => flake.lock (93%) rename template/overlay.nix => overlay.nix (100%) rename {template/pkgs => pkgs}/triton-docker-env-shell.nix (100%) rename {template/pkgs => pkgs}/triton-docker-env.nix (100%) rename {template/pkgs => pkgs}/triton-utils.nix (100%) rename {template/pkgs => pkgs}/utils/cacert-2022-07-19.pem (100%) rename {template/pkgs => pkgs}/utils/ttp.sh (100%) rename {template/pkgs => pkgs}/utils/unset-env.sh (100%) create mode 100644 template/.envrc create mode 100644 template/.gitignore rename template/tritonshell.nix => tritonshell.nix (100%) diff --git a/template/flake.lock b/flake.lock similarity index 93% rename from template/flake.lock rename to flake.lock index c2b460f..159e757 100644 --- a/template/flake.lock +++ b/flake.lock @@ -67,11 +67,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1664538465, - "narHash": "sha256-EnlC7dDKX7X1wlnXkB1gmn9rBZQ0J9+biVTZHw//8us=", + "lastModified": 1665349835, + "narHash": "sha256-UK4urM3iN80UXQ7EaOappDzcisYIuEURFRoGQ/yPkug=", "owner": "nixos", "repo": "nixpkgs", - "rev": "10ecda252ce1b3b1d6403caeadbcc8f30d5ab796", + "rev": "34c5293a71ffdb2fe054eb5288adc1882c1eb0b1", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index d6632d0..427ed7a 100644 --- a/flake.nix +++ b/flake.nix @@ -1,10 +1,78 @@ { - description = "nix flake template for devs & ops environment with triton"; + description = "devshell nix module for triton DevOps shell environment"; - outputs = { self }: { - defaultTemplate = { - description = "nix flake new --template 'git+https://git.greenbaum.cloud/greenbaum.cloud/tritonshell?ref=main' ./tritonshell"; - path = ./template; - }; - }; + inputs.devshell.url = "github:numtide/devshell"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + outputs = { self, flake-utils, devshell, nixpkgs }: + flake-utils.lib.eachSystem [ + "aarch64-linux" + "i686-linux" + "x86_64-darwin" + "x86_64-linux" + ] + ( + system: + let + pkgs = import nixpkgs { + inherit system; + + overlays = [ + devshell.overlay + (import ./overlay.nix) + ]; + }; + in + { + devshellModules.tritonshell = { config, lib, ... }: + with lib; + { + options = { + environment = { + enable = mkEnableOption "triton DevOps shell environment"; + # options 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 = 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 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 = import ./pkgs/triton-docker-env.nix { inherit pkgs; }; + }; + outputs = { self }: { + defaultTemplate = { + description = "nix flake new --template 'git+https://git.greenbaum.cloud/greenbaum.cloud/tritonshell?ref=main' ./tritonshell"; + path = ./template; + }; + }; + } + ); } diff --git a/template/overlay.nix b/overlay.nix similarity index 100% rename from template/overlay.nix rename to overlay.nix diff --git a/template/pkgs/triton-docker-env-shell.nix b/pkgs/triton-docker-env-shell.nix similarity index 100% rename from template/pkgs/triton-docker-env-shell.nix rename to pkgs/triton-docker-env-shell.nix diff --git a/template/pkgs/triton-docker-env.nix b/pkgs/triton-docker-env.nix similarity index 100% rename from template/pkgs/triton-docker-env.nix rename to pkgs/triton-docker-env.nix diff --git a/template/pkgs/triton-utils.nix b/pkgs/triton-utils.nix similarity index 100% rename from template/pkgs/triton-utils.nix rename to pkgs/triton-utils.nix diff --git a/template/pkgs/utils/cacert-2022-07-19.pem b/pkgs/utils/cacert-2022-07-19.pem similarity index 100% rename from template/pkgs/utils/cacert-2022-07-19.pem rename to pkgs/utils/cacert-2022-07-19.pem diff --git a/template/pkgs/utils/ttp.sh b/pkgs/utils/ttp.sh similarity index 100% rename from template/pkgs/utils/ttp.sh rename to pkgs/utils/ttp.sh diff --git a/template/pkgs/utils/unset-env.sh b/pkgs/utils/unset-env.sh similarity index 100% rename from template/pkgs/utils/unset-env.sh rename to pkgs/utils/unset-env.sh diff --git a/template/.envrc b/template/.envrc new file mode 100644 index 0000000..80ffa0d --- /dev/null +++ b/template/.envrc @@ -0,0 +1,3 @@ +# reload when these files change +watch_file flake.nix +use_flake diff --git a/template/.gitignore b/template/.gitignore new file mode 100644 index 0000000..2bbdbfe --- /dev/null +++ b/template/.gitignore @@ -0,0 +1,2 @@ +.direnv +result diff --git a/template/flake.nix b/template/flake.nix index c319f38..bb642e3 100644 --- a/template/flake.nix +++ b/template/flake.nix @@ -1,80 +1,33 @@ { - description = "devshell nix module for triton DevOps shell environment"; + description = "Example devshell using the tritonshell nix module"; - inputs.devshell.url = "github:numtide/devshell"; inputs.flake-utils.url = "github:numtide/flake-utils"; - inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + inputs.devshell.url = "github:numtide/devshell"; + inputs.tritonshell-module.url = "git+https://git.greenbaum.cloud/dev/tritonshell?ref=main"; - outputs = { self, flake-utils, devshell, nixpkgs }: - flake-utils.lib.eachSystem [ - "aarch64-linux" - "i686-linux" - "x86_64-darwin" - "x86_64-linux" - ] - ( - system: - let - pkgs = import nixpkgs { - inherit system; - - overlays = [ - devshell.overlay - (import ./overlay.nix) - ]; + outputs = { self, flake-utils, devshell, tritonshell-module, nixpkgs }: + flake-utils.lib.simpleFlake { + inherit self nixpkgs; + name = "infra-project"; + preOverlays = [ devshell.overlay ]; + shell = { pkgs }: + pkgs.devshell.mkShell { + imports = [ tritonshell-module.devshellModules.x86_64-linux.tritonshell ]; + # Now the tritonshell environment nix module options are available + environment = { + enable = true; + # default options + #cnsBaseDomain = "greenbaum.zone"; + #dataCenters = [ "cgn-1" "lev-1" ]; + #mantaDomain = "eu-central.manta.greenbaum.cloud"; + #tritonApiDomain = "api.greenbaum.cloud"; }; - 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 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; }; - }; - } - ); + # Add additional packages you'd like to be available in your devshell + # PATH here + devshell.packages = with pkgs; [ + #nodejs + ]; + }; + }; } diff --git a/template/tritonshell.nix b/tritonshell.nix similarity index 100% rename from template/tritonshell.nix rename to tritonshell.nix From 7b0e92fa95e7a64578d989cbdcaecf6b1e654cdf Mon Sep 17 00:00:00 2001 From: jhonas Date: Wed, 12 Oct 2022 14:27:33 +0200 Subject: [PATCH 5/6] Locally pin template flake inputs in flake.lock --- template/flake.nix | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/template/flake.nix b/template/flake.nix index bb642e3..4dc898f 100644 --- a/template/flake.nix +++ b/template/flake.nix @@ -1,9 +1,20 @@ { description = "Example devshell using the tritonshell nix module"; - inputs.flake-utils.url = "github:numtide/flake-utils"; - inputs.devshell.url = "github:numtide/devshell"; - inputs.tritonshell-module.url = "git+https://git.greenbaum.cloud/dev/tritonshell?ref=main"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + flake-utils.url = "github:numtide/flake-utils"; + + devshell.url = "github:numtide/devshell"; + devshell.inputs.flake-utils.follows = "flake-utils"; + devshell.inputs.nixpkgs.follows = "nixpkgs"; + + tritonshell-module.url = "git+https://git.greenbaum.cloud/dev/tritonshell?ref=main"; + tritonshell-module.inputs.devshell.follows = "devshell"; + tritonshell-module.inputs.flake-utils.follows = "flake-utils"; + tritonshell-module.inputs.nixpkgs.follows = "nixpkgs"; + }; outputs = { self, flake-utils, devshell, tritonshell-module, nixpkgs }: flake-utils.lib.simpleFlake { From 0eec1c3ebc380d526d9d451b22ac632a28cba5cf Mon Sep 17 00:00:00 2001 From: jhonas Date: Wed, 12 Oct 2022 14:36:52 +0200 Subject: [PATCH 6/6] Update README and comment --- README.md | 12 +++++++++--- template/flake.nix | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9365db4..2dacfbf 100644 --- a/README.md +++ b/README.md @@ -35,14 +35,20 @@ vim ./flake.nix 4. **Ready** to go: ``` -nix develop +nix develop -c $SHELL ``` **Optional**: If you'd like to add **additional packages** to your new tritonshell, you -can do so: just edit `flake.nix` and look for `extraDevshellPkgs`. Packages +can do so: just edit `flake.nix` and look for `devshell.packages`. Packages added here will be pulled from the `nixos-unstable` channel, you can [search for available packages here](https://search.nixos.org/packages?channel=unstable&from=0&size=50&sort=relevance&type=packages&query=hello). -TODO: add `nix-direnv` +You can use `nix-direnv` with this template, [read here how to install it](https://github.com/nix-community/nix-direnv#installation). +Then, just run: +``` +direnv allow +``` +in the newly created `./tritonshell` directory to automatically rebuild the +flake upon changes to the `flake.nix` file. diff --git a/template/flake.nix b/template/flake.nix index 4dc898f..9611593 100644 --- a/template/flake.nix +++ b/template/flake.nix @@ -27,7 +27,7 @@ # Now the tritonshell environment nix module options are available environment = { enable = true; - # default options + # CUSTOMIZE if desired, default options are: #cnsBaseDomain = "greenbaum.zone"; #dataCenters = [ "cgn-1" "lev-1" ]; #mantaDomain = "eu-central.manta.greenbaum.cloud";