mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
docker-cli: add module (#7411)
(cherry picked from commit 729c5e5465)
Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
parent
05d7a84f50
commit
c6a01e54af
6 changed files with 134 additions and 0 deletions
1
.github/labeler.yml
vendored
1
.github/labeler.yml
vendored
|
|
@ -163,6 +163,7 @@
|
||||||
- any-glob-to-any-file:
|
- any-glob-to-any-file:
|
||||||
- modules/services/podman-linux/**/*
|
- modules/services/podman-linux/**/*
|
||||||
- modules/programs/distrobox.nix
|
- modules/programs/distrobox.nix
|
||||||
|
- modules/programs/docker-cli.nix
|
||||||
"desktop-ui":
|
"desktop-ui":
|
||||||
- changed-files:
|
- changed-files:
|
||||||
- any-glob-to-any-file:
|
- any-glob-to-any-file:
|
||||||
|
|
|
||||||
65
modules/programs/docker-cli.nix
Normal file
65
modules/programs/docker-cli.nix
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
inherit (lib)
|
||||||
|
mkIf
|
||||||
|
mkEnableOption
|
||||||
|
mkOption
|
||||||
|
;
|
||||||
|
|
||||||
|
cfg = config.programs.docker-cli;
|
||||||
|
|
||||||
|
jsonFormat = pkgs.formats.json { };
|
||||||
|
in
|
||||||
|
{
|
||||||
|
meta.maintainers = [ lib.maintainers.friedrichaltheide ];
|
||||||
|
|
||||||
|
options.programs.docker-cli = {
|
||||||
|
enable = mkEnableOption "management of docker client config";
|
||||||
|
|
||||||
|
configPath = mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = ".docker/config.json";
|
||||||
|
description = ''
|
||||||
|
Relative path to the user's home directory where the Docker CLI settings should be stored.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
settings = mkOption {
|
||||||
|
type = jsonFormat.type;
|
||||||
|
default = { };
|
||||||
|
example = ''
|
||||||
|
{
|
||||||
|
"proxies" = {
|
||||||
|
"default" = {
|
||||||
|
"httpProxy" = "http://proxy.example.org:3128";
|
||||||
|
"httpsProxy" = "http://proxy.example.org:3128";
|
||||||
|
"noProxy" = "localhost";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
Available configuration options for the Docker CLI see:
|
||||||
|
<https://docs.docker.com/reference/cli/docker/#docker-cli-configuration-file-configjson-properties
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
home = {
|
||||||
|
sessionVariables = {
|
||||||
|
DOCKER_CONFIG = "${config.home.homeDirectory}/${cfg.configPath}";
|
||||||
|
};
|
||||||
|
|
||||||
|
file = {
|
||||||
|
"${cfg.configPath}" = {
|
||||||
|
source = jsonFormat.generate "config.json" cfg.settings;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
4
tests/modules/programs/docker-cli/default.nix
Normal file
4
tests/modules/programs/docker-cli/default.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
docker-cli = ./example-config.nix;
|
||||||
|
docker-cli-empty-config = ./empty-config.nix;
|
||||||
|
}
|
||||||
18
tests/modules/programs/docker-cli/empty-config.nix
Normal file
18
tests/modules/programs/docker-cli/empty-config.nix
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
cfgDocker = config.programs.docker-cli;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
programs.docker-cli = {
|
||||||
|
configPath = ".docker/empty.json";
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
assertFileNotRegex home-path/etc/profile.d/hm-session-vars.sh 'DOCKER_CONFIG'
|
||||||
|
assertPathNotExists home-files/.docker/config.json
|
||||||
|
assertPathNotExists home-files/${cfgDocker.configPath}
|
||||||
|
'';
|
||||||
|
}
|
||||||
9
tests/modules/programs/docker-cli/example-config.json
Normal file
9
tests/modules/programs/docker-cli/example-config.json
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"proxies": {
|
||||||
|
"default": {
|
||||||
|
"httpProxy": "http://proxy.example.org:3128",
|
||||||
|
"httpsProxy": "http://proxy.example.org:3128",
|
||||||
|
"noProxy": "localhost"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
37
tests/modules/programs/docker-cli/example-config.nix
Normal file
37
tests/modules/programs/docker-cli/example-config.nix
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
programs.docker-cli = {
|
||||||
|
enable = true;
|
||||||
|
|
||||||
|
configPath = ".docker/config2.json";
|
||||||
|
|
||||||
|
settings = {
|
||||||
|
"proxies" = {
|
||||||
|
"default" = {
|
||||||
|
"httpProxy" = "http://proxy.example.org:3128";
|
||||||
|
"httpsProxy" = "http://proxy.example.org:3128";
|
||||||
|
"noProxy" = "localhost";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
nmt.script =
|
||||||
|
let
|
||||||
|
cfgDocker = config.programs.docker-cli;
|
||||||
|
configTestPath = "home-files/${cfgDocker.configPath}";
|
||||||
|
configHomePath = "/home/hm-user/${cfgDocker.configPath}";
|
||||||
|
in
|
||||||
|
''
|
||||||
|
assertFileContains home-path/etc/profile.d/hm-session-vars.sh \
|
||||||
|
'export DOCKER_CONFIG="${configHomePath}"'
|
||||||
|
|
||||||
|
assertPathNotExists home-files/.docker/config.json
|
||||||
|
assertFileExists ${configTestPath}
|
||||||
|
assertFileContent ${configTestPath} \
|
||||||
|
${./example-config.json}
|
||||||
|
'';
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue