From 9f130ca346aab4938009f575b4bd673d67fb5cd4 Mon Sep 17 00:00:00 2001 From: jhonas Date: Wed, 12 Oct 2022 14:14:05 +0200 Subject: [PATCH] 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