From 1d3f439cd8e8c95d142f78f8d1bd253c6901742d Mon Sep 17 00:00:00 2001 From: Nicola Squartini Date: Wed, 15 Nov 2023 23:25:44 +0100 Subject: [PATCH] openstackclient: add module (#4530) Co-authored-by: Sumner Evans --- modules/lib/maintainers.nix | 5 ++ modules/misc/news.nix | 9 ++- modules/modules.nix | 1 + modules/programs/openstackclient.nix | 73 +++++++++++++++++++ tests/default.nix | 1 + .../openstackclient/clouds-public.yaml | 4 + .../programs/openstackclient/clouds.yaml | 8 ++ .../programs/openstackclient/default.nix | 1 + .../openstackclient/openstackclient.nix | 35 +++++++++ 9 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 modules/programs/openstackclient.nix create mode 100644 tests/modules/programs/openstackclient/clouds-public.yaml create mode 100644 tests/modules/programs/openstackclient/clouds.yaml create mode 100644 tests/modules/programs/openstackclient/default.nix create mode 100644 tests/modules/programs/openstackclient/openstackclient.nix diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 534e4892e..b7cbba3ec 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -420,6 +420,11 @@ keys = [{ fingerprint = "75F0 AB7C FE01 D077 AEE6 CAFD 353E 4A18 EE0F AB72"; }]; }; + tensor5 = { + github = "tensor5"; + githubId = 1545895; + name = "Nicola Squartini"; + }; toastal = { email = "toastal+nix@posteo.net"; matrix = "@toastal:matrix.org"; diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 82ad52877..d8841156f 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1116,7 +1116,7 @@ in can control it by using the `qt5ct` and `qt6ct` applications; - `qt.style.name = "kvantum"`: override the style by using themes written in SVG. Supports many popular themes. - ''; + ''; } { @@ -1274,6 +1274,13 @@ in ''; } + { + time = "2023-10-04T18:35:42+00:00"; + message = '' + A new module is available: 'programs.openstackclient'. + ''; + } + { time = "2023-10-17T06:33:24+00:00"; condition = hostPlatform.isLinux; diff --git a/modules/modules.nix b/modules/modules.nix index 12163edc7..e49e7e8bf 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -165,6 +165,7 @@ let ./programs/offlineimap.nix ./programs/oh-my-posh.nix ./programs/opam.nix + ./programs/openstackclient.nix ./programs/pandoc.nix ./programs/papis.nix ./programs/password-store.nix diff --git a/modules/programs/openstackclient.nix b/modules/programs/openstackclient.nix new file mode 100644 index 000000000..98d68a2f2 --- /dev/null +++ b/modules/programs/openstackclient.nix @@ -0,0 +1,73 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.programs.openstackclient; + yamlFormat = pkgs.formats.yaml { }; +in { + meta.maintainers = [ lib.hm.maintainers.tensor5 ]; + + options.programs.openstackclient = { + enable = lib.mkEnableOption "OpenStack command-line client"; + + package = lib.mkPackageOption pkgs "openstackclient" { }; + + clouds = lib.mkOption { + type = lib.types.submodule { freeformType = yamlFormat.type; }; + default = { }; + example = lib.literalExpression '' + { + my-infra = { + cloud = "example-cloud"; + auth = { + project_id = "0123456789abcdef0123456789abcdef"; + username = "openstack"; + }; + region_name = "XXX"; + interface = "internal"; + }; + } + ''; + description = '' + Configuration needed to connect to one or more clouds. + + Do not include passwords here as they will be publicly readable in the Nix store. + Configuration written to {file}`$XDG_CONFIG_HOME/openstack/clouds.yaml`. + See . + ''; + }; + + publicClouds = lib.mkOption { + type = lib.types.submodule { freeformType = yamlFormat.type; }; + default = { }; + example = lib.literalExpression '' + { + example-cloud = { + auth = { + auth_url = "https://identity.cloud.example.com/v2.0"; + }; + }; + }; + ''; + description = '' + Public information about clouds. + + Configuration written to {file}`$XDG_CONFIG_HOME/openstack/clouds-public.yaml`. + See . + ''; + }; + }; + + config = lib.mkIf cfg.enable { + home.packages = [ cfg.package ]; + + xdg.configFile."openstack/clouds.yaml".source = yamlFormat.generate + "openstackclient-clouds-yaml-${config.home.username}" { + clouds = cfg.clouds; + }; + + xdg.configFile."openstack/clouds-public.yaml".source = yamlFormat.generate + "openstackclient-clouds-public-yaml-${config.home.username}" { + public-clouds = cfg.publicClouds; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index db4e1d05f..6fbd09bc8 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -118,6 +118,7 @@ import nmt { ./modules/programs/nnn ./modules/programs/nushell ./modules/programs/oh-my-posh + ./modules/programs/openstackclient ./modules/programs/pandoc ./modules/programs/papis ./modules/programs/pet diff --git a/tests/modules/programs/openstackclient/clouds-public.yaml b/tests/modules/programs/openstackclient/clouds-public.yaml new file mode 100644 index 000000000..26bf551ff --- /dev/null +++ b/tests/modules/programs/openstackclient/clouds-public.yaml @@ -0,0 +1,4 @@ +public-clouds: + example-cloud: + auth: + auth_url: https://identity.cloud.example.com/v2.0 diff --git a/tests/modules/programs/openstackclient/clouds.yaml b/tests/modules/programs/openstackclient/clouds.yaml new file mode 100644 index 000000000..c73d350ca --- /dev/null +++ b/tests/modules/programs/openstackclient/clouds.yaml @@ -0,0 +1,8 @@ +clouds: + my-infra: + auth: + project_id: 0123456789abcdef0123456789abcdef + username: openstack + cloud: example-cloud + interface: internal + region_name: XXX diff --git a/tests/modules/programs/openstackclient/default.nix b/tests/modules/programs/openstackclient/default.nix new file mode 100644 index 000000000..846b99724 --- /dev/null +++ b/tests/modules/programs/openstackclient/default.nix @@ -0,0 +1 @@ +{ openstackclient = ./openstackclient.nix; } diff --git a/tests/modules/programs/openstackclient/openstackclient.nix b/tests/modules/programs/openstackclient/openstackclient.nix new file mode 100644 index 000000000..0c5e1f0bc --- /dev/null +++ b/tests/modules/programs/openstackclient/openstackclient.nix @@ -0,0 +1,35 @@ +{ ... }: + +{ + programs.openstackclient = { + enable = true; + clouds = { + my-infra = { + cloud = "example-cloud"; + auth = { + project_id = "0123456789abcdef0123456789abcdef"; + username = "openstack"; + }; + region_name = "XXX"; + interface = "internal"; + }; + }; + publicClouds = { + example-cloud = { + auth = { auth_url = "https://identity.cloud.example.com/v2.0"; }; + }; + }; + + }; + + test.stubs.openstackclient = { }; + + nmt.script = '' + assertFileExists home-files/.config/openstack/clouds.yaml + assertFileContent home-files/.config/openstack/clouds.yaml \ + ${./clouds.yaml} + assertFileExists home-files/.config/openstack/clouds-public.yaml + assertFileContent home-files/.config/openstack/clouds-public.yaml \ + ${./clouds-public.yaml} + ''; +}