Skip to content

Commit

Permalink
Move extraConfig blocks for SSH config to use home-manager built in f…
Browse files Browse the repository at this point in the history
…unctions (#74)
  • Loading branch information
sonnius authored May 2, 2024
1 parent 9921482 commit 82fc40c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 53 deletions.
41 changes: 19 additions & 22 deletions modules/shared/home-manager.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ let name = "Dustin Lyons";
};
extraConfig = {
init.defaultBranch = "main";
core = {
core = {
editor = "vim";
autocrlf = "input";
};
Expand Down Expand Up @@ -267,30 +267,27 @@ let name = "Dustin Lyons";

ssh = {
enable = true;

extraConfig = lib.mkMerge [
(lib.mkIf pkgs.stdenv.hostPlatform.isLinux
''
Include /home/${user}/.ssh/config_external
'')
(lib.mkIf pkgs.stdenv.hostPlatform.isDarwin
''
Include /Users/${user}/.ssh/config_external
'')
''
Host github.com
Hostname github.com
IdentitiesOnly yes
''
includes = [
(lib.mkIf pkgs.stdenv.hostPlatform.isLinux
''
IdentityFile /home/${user}/.ssh/id_github
'')
"/home/${user}/.ssh/config_external"
)
(lib.mkIf pkgs.stdenv.hostPlatform.isDarwin
''
IdentityFile /Users/${user}/.ssh/id_github
'')
"/Users/${user}/.ssh/config_external"
)
];
matchBlocks = {
"github.com" = {
identitiesOnly = true;
identityFile = [
(lib.mkIf pkgs.stdenv.hostPlatform.isLinux
"/home/${user}/.ssh/id_github"
)
(lib.mkIf pkgs.stdenv.hostPlatform.isDarwin
"/Users/${user}/.ssh/id_github"
)
];
};
};
};

tmux = {
Expand Down
4 changes: 2 additions & 2 deletions templates/starter-with-secrets/modules/darwin/secrets.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

let user = "%USER%"; in
{
age.identityPaths = [
age.identityPaths = [
"/Users/${user}/.ssh/id_ed25519"
];

Expand All @@ -13,7 +13,7 @@ let user = "%USER%"; in
# instead, you can reference the age files and specify the symlink path here. Then add your
# public key in shared/files.nix.
#
# If you change the key name, you'll need to update the SSH extraConfig in shared/home-manager.nix
# If you change the key name, you'll need to update the SSH configuration in shared/home-manager.nix
# so Github reads it correctly.

#
Expand Down
2 changes: 1 addition & 1 deletion templates/starter-with-secrets/modules/nixos/secrets.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let user = "%USER%"; in
# instead, you can reference the age files and specify the symlink path here. Then add your
# public key in shared/files.nix.
#
# If you change the key name, you'll need to update the SSH extraConfig in shared/home-manager.nix
# If you change the key name, you'll need to update the SSH configuration in shared/home-manager.nix
# so Github reads it correctly.

#
Expand Down
33 changes: 19 additions & 14 deletions templates/starter-with-secrets/modules/shared/home-manager.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ let name = "%NAME%";
};
extraConfig = {
init.defaultBranch = "main";
core = {
core = {
editor = "vim";
autocrlf = "input";
};
Expand Down Expand Up @@ -261,22 +261,27 @@ let name = "%NAME%";

ssh = {
enable = true;

extraConfig = lib.mkMerge [
''
Host github.com
Hostname github.com
IdentitiesOnly yes
''
includes = [
(lib.mkIf pkgs.stdenv.hostPlatform.isLinux
''
IdentityFile /home/${user}/.ssh/id_github
'')
"/home/${user}/.ssh/config_external"
)
(lib.mkIf pkgs.stdenv.hostPlatform.isDarwin
''
IdentityFile /Users/${user}/.ssh/id_github
'')
"/Users/${user}/.ssh/config_external"
)
];
matchBlocks = {
"github.com" = {
identitiesOnly = true;
identityFile = [
(lib.mkIf pkgs.stdenv.hostPlatform.isLinux
"/home/${user}/.ssh/id_github"
)
(lib.mkIf pkgs.stdenv.hostPlatform.isDarwin
"/Users/${user}/.ssh/id_github"
)
];
};
};
};

tmux = {
Expand Down
33 changes: 19 additions & 14 deletions templates/starter/modules/shared/home-manager.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ let name = "%NAME%";
};
extraConfig = {
init.defaultBranch = "main";
core = {
core = {
editor = "vim";
autocrlf = "input";
};
Expand Down Expand Up @@ -253,22 +253,27 @@ let name = "%NAME%";

ssh = {
enable = true;

extraConfig = lib.mkMerge [
''
Host github.com
Hostname github.com
IdentitiesOnly yes
''
includes = [
(lib.mkIf pkgs.stdenv.hostPlatform.isLinux
''
IdentityFile /home/${user}/.ssh/id_github
'')
"/home/${user}/.ssh/config_external"
)
(lib.mkIf pkgs.stdenv.hostPlatform.isDarwin
''
IdentityFile /Users/${user}/.ssh/id_github
'')
"/Users/${user}/.ssh/config_external"
)
];
matchBlocks = {
"github.com" = {
identitiesOnly = true;
identityFile = [
(lib.mkIf pkgs.stdenv.hostPlatform.isLinux
"/home/${user}/.ssh/id_github"
)
(lib.mkIf pkgs.stdenv.hostPlatform.isDarwin
"/Users/${user}/.ssh/id_github"
)
];
};
};
};

tmux = {
Expand Down

0 comments on commit 82fc40c

Please sign in to comment.