Skip to content

Commit

Permalink
Nix: Add public SSH key
Browse files Browse the repository at this point in the history
I want to start making this part of my setup so I don't have to do all
of this manually...
  • Loading branch information
Mange committed Dec 21, 2024
1 parent d37faa2 commit ac517a3
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions data/ssh-keys/id_daddy.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK339UoUDLK3K4EtgW6Z20Q1mYlBL9XdAnLgO3BtkI4z daddy
1 change: 1 addition & 0 deletions data/ssh-keys/id_mange_2024.pub
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKTvo4U3B3I7tpAOq4VAgSmzJbVVMNdsEgTlPaYOBOEt mange+2024@bergmark
18 changes: 13 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,22 @@

# NixOS configuration entrypoint
# Available through 'nixos-rebuild switch --flake .#your-hostname'
nixosConfigurations = {
nixosConfigurations = let
specialArgs = {
inherit inputs outputs;
rootPath = ./.;
};
in {
socia = nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs outputs; };
inherit specialArgs;
modules = [./systems/socia/configuration.nix];
};
vera = nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs outputs; };
inherit specialArgs;
modules = [./systems/vera/configuration.nix];
};
porto = nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs outputs; };
inherit specialArgs;
modules = [./systems/porto/configuration.nix];
};
};
Expand All @@ -71,7 +76,10 @@
# Available through 'home-manager --flake .#your-username@your-hostname'
homeConfigurations = let
homeConfig = home-manager.lib.homeManagerConfiguration;
extraSpecialArgs = { inherit inputs outputs; };
extraSpecialArgs = {
inherit inputs outputs;
rootPath = ./.;
};
in {
"mange@socia" = homeConfig {
extraSpecialArgs = extraSpecialArgs // {
Expand Down
10 changes: 9 additions & 1 deletion home/_roles/pc/security.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Keyring, SSH, GPG stuff
{ config, pkgs, lib, ... }: {
{ config, pkgs, lib, rootPath, ... }: let
sshPubKeys = lib.filesystem.listFilesRecursive (rootPath + /data/ssh-keys);
sshKeyFiles = lib.lists.map (file: {
".ssh/${builtins.baseNameOf file}" = { source = file; };
}) sshPubKeys;
in {
# Install SSH public keys
home.file = (lib.attrsets.mergeAttrsList sshKeyFiles);

# Keyring and gpg agent
services.gnome-keyring.enable = true;
home.sessionVariables.SSH_AUTH_SOCK = "$XDG_RUNTIME_DIR/keyring/ssh"; # gnome-keyring
Expand Down
7 changes: 3 additions & 4 deletions systems/_roles/pc/users.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, ... }: {
{ pkgs, rootPath, ... }: {
security.polkit.enable = true;
security.sudo.enable = true;
services.accounts-daemon.enable = true;
Expand All @@ -14,9 +14,8 @@
"input" # Control LEDs
];
shell = pkgs.zsh;
openssh.authorizedKeys.keys = [
# TODO: Add your SSH public key(s) here, if you plan on using SSH to connect
openssh.authorizedKeys.keyFiles = [
(rootPath + /data/ssh-keys/id_mange_2024.pub)
];
};

}

0 comments on commit ac517a3

Please sign in to comment.