ssh: remove top level options

This commit is contained in:
Aguirre Matteo 2025-08-22 12:37:35 -03:00 committed by Austin Horstman
parent 59aabcd3db
commit 3882f88691
23 changed files with 370 additions and 226 deletions

View file

@ -1,18 +0,0 @@
{ config, lib, ... }:
{
config = {
programs.ssh = {
enable = true;
};
home.file.assertions.text = builtins.toJSON (
map (a: a.message) (lib.filter (a: !a.assertion) config.assertions)
);
nmt.script = ''
assertFileExists home-files/.ssh/config
assertFileContent home-files/.ssh/config ${./default-config-expected.conf}
assertFileContent home-files/assertions ${./no-assertions.json}
'';
};
}

View file

@ -1,9 +1,11 @@
{
ssh-defaults = ./default-config.nix;
ssh-old-defaults = ./old-defaults.nix;
ssh-old-defaults-extra-config = ./old-defaults-extra-config.nix;
ssh-extra-config-no-default-host = ./extra-config-no-default-host.nix;
ssh-renamed-options = ./renamed-options.nix;
ssh-includes = ./includes.nix;
ssh-match-blocks = ./match-blocks-attrs.nix;
ssh-match-blocks-match-and-hosts = ./match-blocks-match-and-hosts.nix;
ssh-forwards-dynamic-valid-bind-no-asserts = ./forwards-dynamic-valid-bind-no-asserts.nix;
ssh-forwards-dynamic-bind-path-with-port-asserts = ./forwards-dynamic-bind-path-with-port-asserts.nix;
ssh-forwards-local-bind-path-with-port-asserts = ./forwards-local-bind-path-with-port-asserts.nix;

View file

@ -0,0 +1,16 @@
Host *
ForwardAgent no
ServerAliveInterval 0
ServerAliveCountMax 3
Compression no
AddKeysToAgent no
HashKnownHosts no
UserKnownHostsFile ~/.ssh/known_hosts
ControlMaster no
ControlPath ~/.ssh/master-%r@%n:%p
ControlPersist no
MyExtraOption no
AnotherOption 3

View file

@ -0,0 +1,14 @@
{
programs.ssh = {
enable = true;
enableDefaultConfig = false;
extraConfig = ''
MyExtraOption no
AnotherOption 3
'';
};
test.asserts.assertions.expected = [
''Cannot set `programs.ssh.extraConfig` if `programs.ssh.matchBlocks."*"` (default host config) is not declared.''
];
}

View file

@ -2,6 +2,7 @@
config = {
programs.ssh = {
enable = true;
enableDefaultConfig = false;
matchBlocks = {
dynamicBindPathWithPort = {
dynamicForwards = [

View file

@ -3,16 +3,5 @@ Host dynamicBindAddressWithPort
Host dynamicBindPathNoPort
DynamicForward /run/user/1000/gnupg/S.gpg-agent.extra
Host *
ForwardAgent no
AddKeysToAgent no
Compression no
ServerAliveInterval 0
ServerAliveCountMax 3
HashKnownHosts no
UserKnownHostsFile ~/.ssh/known_hosts
ControlMaster no
ControlPath ~/.ssh/master-%r@%n:%p
ControlPersist no

View file

@ -3,6 +3,7 @@
config = {
programs.ssh = {
enable = true;
enableDefaultConfig = false;
matchBlocks = {
dynamicBindPathNoPort = {
dynamicForwards = [

View file

@ -2,6 +2,7 @@
config = {
programs.ssh = {
enable = true;
enableDefaultConfig = false;
matchBlocks = {
localBindPathWithPort = {
localForwards = [

View file

@ -2,6 +2,7 @@
config = {
programs.ssh = {
enable = true;
enableDefaultConfig = false;
matchBlocks = {
localHostPathWithPort = {
localForwards = [

View file

@ -2,6 +2,7 @@
config = {
programs.ssh = {
enable = true;
enableDefaultConfig = false;
matchBlocks = {
remoteBindPathWithPort = {
remoteForwards = [

View file

@ -2,6 +2,7 @@
config = {
programs.ssh = {
enable = true;
enableDefaultConfig = false;
matchBlocks = {
remoteHostPathWithPort = {
remoteForwards = [

View file

@ -7,6 +7,7 @@
config = {
programs.ssh = {
enable = true;
enableDefaultConfig = false;
includes = [
"config.d/*"
"other/dir"

View file

@ -16,16 +16,5 @@ Host xyz
Host ordered
Port 1
Host *
ForwardAgent no
AddKeysToAgent no
Compression no
ServerAliveInterval 0
ServerAliveCountMax 3
HashKnownHosts no
UserKnownHostsFile ~/.ssh/known_hosts
ControlMaster no
ControlPath ~/.ssh/master-%r@%n:%p
ControlPersist no

View file

@ -3,6 +3,7 @@
config = {
programs.ssh = {
enable = true;
enableDefaultConfig = false;
matchBlocks = {
abc = {
identityFile = null;

View file

@ -5,16 +5,5 @@ Host abc
Match host xyz canonical
Port 2223
Host *
ForwardAgent no
AddKeysToAgent no
Compression no
ServerAliveInterval 0
ServerAliveCountMax 3
HashKnownHosts no
UserKnownHostsFile ~/.ssh/known_hosts
ControlMaster no
ControlPath ~/.ssh/master-%r@%n:%p
ControlPersist no

View file

@ -3,6 +3,7 @@
config = {
programs.ssh = {
enable = true;
enableDefaultConfig = false;
matchBlocks = {
abc = {
port = 2222;

View file

@ -2,14 +2,13 @@
Host *
ForwardAgent no
AddKeysToAgent no
Compression no
ServerAliveInterval 0
ServerAliveCountMax 3
Compression no
AddKeysToAgent no
HashKnownHosts no
UserKnownHostsFile ~/.ssh/known_hosts
ControlMaster no
ControlPath ~/.ssh/master-%r@%n:%p
ControlPersist no

View file

@ -0,0 +1,16 @@
Host *
ForwardAgent no
ServerAliveInterval 0
ServerAliveCountMax 3
Compression no
AddKeysToAgent no
HashKnownHosts no
UserKnownHostsFile ~/.ssh/known_hosts
ControlMaster no
ControlPath ~/.ssh/master-%r@%n:%p
ControlPersist no
MyExtraOption no
AnotherOption 3

View file

@ -0,0 +1,24 @@
{
programs.ssh = {
enable = true;
extraConfig = ''
MyExtraOption no
AnotherOption 3
'';
};
test.asserts.warnings.expected = [
''
`programs.ssh` default values will be removed in the future.
Consider setting `programs.ssh.enableDefaultConfig` to false,
and manually set the default values you want to keep at
`programs.ssh.matchBlocks."*"`.
''
];
nmt.script = ''
assertFileExists home-files/.ssh/config
assertFileContent home-files/.ssh/config \
${./old-defaults-extra-config-expected.conf}
'';
}

View file

@ -0,0 +1,18 @@
{
programs.ssh.enable = true;
test.asserts.warnings.expected = [
''
`programs.ssh` default values will be removed in the future.
Consider setting `programs.ssh.enableDefaultConfig` to false,
and manually set the default values you want to keep at
`programs.ssh.matchBlocks."*"`.
''
];
nmt.script = ''
assertFileExists home-files/.ssh/config
assertFileContent home-files/.ssh/config \
${./old-defaults-expected.conf}
'';
}

View file

@ -0,0 +1,14 @@
Host *
ForwardAgent yes
ServerAliveInterval 1
ServerAliveCountMax 2
Compression yes
AddKeysToAgent yes
HashKnownHosts yes
UserKnownHostsFile ~/.ssh/my_known_hosts
ControlMaster yes
ControlPath ~/.ssh/myfile-%r@%n:%p
ControlPersist 10m

View file

@ -0,0 +1,46 @@
{ lib, options, ... }:
{
programs.ssh = {
enable = true;
enableDefaultConfig = false;
forwardAgent = true;
addKeysToAgent = "yes";
compression = true;
serverAliveInterval = 1;
serverAliveCountMax = 2;
hashKnownHosts = true;
userKnownHostsFile = "~/.ssh/my_known_hosts";
controlMaster = "yes";
controlPath = "~/.ssh/myfile-%r@%n:%p";
controlPersist = "10m";
};
test.asserts.warnings.expected =
let
renamedOptions = [
"controlPersist"
"controlPath"
"controlMaster"
"userKnownHostsFile"
"hashKnownHosts"
"serverAliveCountMax"
"serverAliveInterval"
"compression"
"addKeysToAgent"
"forwardAgent"
];
in
map (
o:
"The option `programs.ssh.${o}' defined in ${
lib.showFiles options.programs.ssh.${o}.files
} has been renamed to `programs.ssh.matchBlocks.*.${o}'."
) renamedOptions;
nmt.script = ''
assertFileExists home-files/.ssh/config
assertFileContent home-files/.ssh/config \
${./renamed-options-expected.conf}
'';
}