From 5fa6274d0d14555e7f5c77ff0eab89d4446d850c Mon Sep 17 00:00:00 2001 From: hauskens Date: Mon, 12 Aug 2024 23:06:48 +0200 Subject: [PATCH] lazydocker: add module --- modules/modules.nix | 1 + modules/programs/lazydocker.nix | 62 +++++++++++++++++++ tests/default.nix | 1 + .../programs/lazydocker/custom-settings.nix | 17 +++++ .../programs/lazydocker/custom-settings.yml | 9 +++ .../programs/lazydocker/default-settings.nix | 9 +++ tests/modules/programs/lazydocker/default.nix | 5 ++ tests/modules/programs/lazydocker/default.yml | 2 + 8 files changed, 106 insertions(+) create mode 100644 modules/programs/lazydocker.nix create mode 100644 tests/modules/programs/lazydocker/custom-settings.nix create mode 100644 tests/modules/programs/lazydocker/custom-settings.yml create mode 100644 tests/modules/programs/lazydocker/default-settings.nix create mode 100644 tests/modules/programs/lazydocker/default.nix create mode 100644 tests/modules/programs/lazydocker/default.yml diff --git a/modules/modules.nix b/modules/modules.nix index 5b100d474..e594f0d92 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -140,6 +140,7 @@ let ./programs/khard.nix ./programs/kitty.nix ./programs/kodi.nix + ./programs/lazydocker.nix ./programs/lazygit.nix ./programs/ledger.nix ./programs/less.nix diff --git a/modules/programs/lazydocker.nix b/modules/programs/lazydocker.nix new file mode 100644 index 000000000..03848cec1 --- /dev/null +++ b/modules/programs/lazydocker.nix @@ -0,0 +1,62 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.lazydocker; + + yamlFormat = pkgs.formats.yaml { }; + + inherit (pkgs.stdenv.hostPlatform) isDarwin; + +in { + meta.maintainers = [ hm.maintainers.hausken ]; + + options.programs.lazydocker = { + enable = mkEnableOption + "lazydocker, a simple terminal UI for both docker and docker compose"; + + package = mkPackageOption pkgs "lazydocker" { }; + + settings = mkOption { + type = yamlFormat.type; + default = { + commandTemplates.dockerCompose = + "docker compose"; # Lazydocker uses docker-compose by default which will not work + }; + example = literalExpression '' + { + gui.theme = { + activeBorderColor = ["red" "bold"]; + inactiveBorderColor = ["blue"]; + }; + commandTemplates.dockerCompose = "docker compose compose -f docker-compose.yml"; + } + ''; + description = '' + Configuration written to + {file}`$XDG_CONFIG_HOME/lazydocker/config.yml` + on Linux or on Darwin if [](#opt-xdg.enable) is set, otherwise + {file}`~/Library/Application Support/jesseduffield/lazydocker/config.yml`. + See + + for supported values. + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + home.file."Library/Application Support/jesseduffield/lazydocker/config.yml" = + mkIf (cfg.settings != { } && (isDarwin && !config.xdg.enable)) { + source = yamlFormat.generate "lazydocker-config" cfg.settings; + }; + + xdg.configFile."lazydocker/config.yml" = + mkIf (cfg.settings != { } && !(isDarwin && !config.xdg.enable)) { + source = yamlFormat.generate "lazydocker-config" cfg.settings; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index a5e7fe9e1..a96c0f1a8 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -96,6 +96,7 @@ in import nmtSrc { ./modules/programs/khard ./modules/programs/kitty ./modules/programs/ledger + ./modules/programs/lazydocker ./modules/programs/less ./modules/programs/lf ./modules/programs/lsd diff --git a/tests/modules/programs/lazydocker/custom-settings.nix b/tests/modules/programs/lazydocker/custom-settings.nix new file mode 100644 index 000000000..b2918339a --- /dev/null +++ b/tests/modules/programs/lazydocker/custom-settings.nix @@ -0,0 +1,17 @@ +{ ... }: { + programs.lazydocker = { + enable = true; + settings = { + commandTemplates.dockerCompose = "docker compose"; + gui.theme = { + activeBorderColor = [ "red" "bold" ]; + inactiveBorderColor = [ "blue" ]; + }; + }; + }; + nmt.script = '' + assertFileExists home-files/.config/lazydocker/config.yml + assertFileContent home-files/.config/lazydocker/config.yml \ + ${./custom-settings.yml} + ''; +} diff --git a/tests/modules/programs/lazydocker/custom-settings.yml b/tests/modules/programs/lazydocker/custom-settings.yml new file mode 100644 index 000000000..91022449f --- /dev/null +++ b/tests/modules/programs/lazydocker/custom-settings.yml @@ -0,0 +1,9 @@ +commandTemplates: + dockerCompose: docker compose +gui: + theme: + activeBorderColor: + - red + - bold + inactiveBorderColor: + - blue diff --git a/tests/modules/programs/lazydocker/default-settings.nix b/tests/modules/programs/lazydocker/default-settings.nix new file mode 100644 index 000000000..0b4050765 --- /dev/null +++ b/tests/modules/programs/lazydocker/default-settings.nix @@ -0,0 +1,9 @@ +{ ... }: { + programs.lazydocker.enable = true; + + nmt.script = '' + assertFileExists home-files/.config/lazydocker/config.yml + assertFileContent home-files/.config/lazydocker/config.yml \ + ${./default.yml} + ''; +} diff --git a/tests/modules/programs/lazydocker/default.nix b/tests/modules/programs/lazydocker/default.nix new file mode 100644 index 000000000..7478fb9dc --- /dev/null +++ b/tests/modules/programs/lazydocker/default.nix @@ -0,0 +1,5 @@ +{ + lazydocker-default-settings = ./default-settings.nix; + lazydocker-custom-settings = ./custom-settings.nix; +} + diff --git a/tests/modules/programs/lazydocker/default.yml b/tests/modules/programs/lazydocker/default.yml new file mode 100644 index 000000000..abc65b784 --- /dev/null +++ b/tests/modules/programs/lazydocker/default.yml @@ -0,0 +1,2 @@ +commandTemplates: + dockerCompose: docker compose