sync sops and users

Signed-off-by: unexplrd <unexplrd@linerds.us>
This commit is contained in:
2025-04-06 13:38:15 +03:00
parent d5521a468d
commit 1f0bbc9daf
4 changed files with 60 additions and 70 deletions

View File

@ -3,9 +3,15 @@
inputs, inputs,
... ...
}: let }: let
s = inputs.mysecrets; inherit (inputs) mysecrets;
hostname = config.networking.hostName; # TODO: stop relying on networking.hostName
sopsFile = "${s}/hosts/${hostname}.yaml"; inherit (config.networking) hostName;
sopsFile = mysecrets + "/hosts/${hostName}.yaml";
dotSsh = name: "/home/user/.ssh/" + name;
sshKey = {
mode = "0400";
owner = "user";
};
in { in {
imports = with inputs; [ imports = with inputs; [
sops-nix.nixosModules.sops sops-nix.nixosModules.sops
@ -17,45 +23,39 @@ in {
keyFile = "/var/lib/sops-nix/key.txt"; keyFile = "/var/lib/sops-nix/key.txt";
generateKey = true; generateKey = true;
}; };
defaultSopsFile = "${s}/common.yaml"; defaultSopsFile = mysecrets + "/common.yaml";
secrets = { secrets = {
"user-password-hashed".neededForUsers = true; "user-password-hashed".neededForUsers = true;
"ssh-config" = { "ssh-config" = {
path = "/home/user/.ssh/config"; path = dotSsh "config";
mode = "0400"; mode = "0400";
owner = "user"; owner = "user";
}; };
"ssh-${hostname}-user" = { "ssh-${hostName}-user" = {
inherit sopsFile; inherit sopsFile;
path = "/home/user/.ssh/id_ed25519"; inherit (sshKey) mode owner;
mode = "0400"; path = dotSsh "id_ed25519";
owner = "user";
}; };
"ssh-${hostname}-user.pub" = { "ssh-${hostName}-user.pub" = {
inherit sopsFile; inherit sopsFile;
path = "/home/user/.ssh/id_ed25519.pub"; inherit (sshKey) mode owner;
mode = "0400"; path = dotSsh "id_ed25519.pub";
owner = "user";
}; };
"ssh-unexplrd" = { "ssh-unexplrd" = {
path = "/home/user/.ssh/id_unexplrd_ed25519"; inherit (sshKey) mode owner;
mode = "0400"; path = dotSsh "id_unexplrd_ed25519";
owner = "user";
}; };
"ssh-unexplrd.pub" = { "ssh-unexplrd.pub" = {
path = "/home/user/.ssh/id_unexplrd_ed25519.pub"; inherit (sshKey) mode owner;
mode = "0400"; path = dotSsh "id_unexplrd_ed25519.pub";
owner = "user";
}; };
"ssh-uni" = { "ssh-uni" = {
path = "/home/user/.ssh/id_uni_ed25519"; inherit (sshKey) mode owner;
mode = "0400"; path = dotSsh "id_uni_ed25519";
owner = "user";
}; };
"ssh-uni.pub" = { "ssh-uni.pub" = {
path = "/home/user/.ssh/id_uni_ed25519.pub"; inherit (sshKey) mode owner;
mode = "0400"; path = dotSsh "id_uni_ed25519.pub";
owner = "user";
}; };
}; };
}; };

View File

@ -3,9 +3,15 @@
inputs, inputs,
... ...
}: let }: let
s = inputs.mysecrets; inherit (inputs) mysecrets;
hostname = config.networking.hostName; # TODO: stop relying on networking.hostName
sopsFile = "${s}/hosts/${hostname}.yaml"; inherit (config.networking) hostName;
sopsFile = mysecrets + "/hosts/${hostName}.yaml";
dotSsh = name: "/home/user/.ssh/" + name;
sshKey = {
mode = "0400";
owner = "user";
};
in { in {
imports = with inputs; [ imports = with inputs; [
sops-nix.nixosModules.sops sops-nix.nixosModules.sops
@ -17,45 +23,38 @@ in {
keyFile = "/var/lib/sops-nix/key.txt"; keyFile = "/var/lib/sops-nix/key.txt";
generateKey = true; generateKey = true;
}; };
defaultSopsFile = "${s}/common.yaml"; defaultSopsFile = mysecrets + "/common.yaml";
secrets = { secrets = {
"user-password-hashed".neededForUsers = true; "user-password-hashed".neededForUsers = true;
"ssh-config" = { "ssh-config" = {
path = "/home/user/.ssh/config"; inherit (sshKey) mode owner;
mode = "0400"; path = dotSsh "config";
owner = "user";
}; };
"ssh-${hostname}-user" = { "ssh-${hostName}-user" = {
inherit sopsFile; inherit sopsFile;
path = "/home/user/.ssh/id_ed25519"; inherit (sshKey) mode owner;
mode = "0400"; path = dotSsh "id_ed25519";
owner = "user";
}; };
"ssh-${hostname}-user.pub" = { "ssh-${hostName}-user.pub" = {
inherit sopsFile; inherit sopsFile;
path = "/home/user/.ssh/id_ed25519.pub"; inherit (sshKey) mode owner;
mode = "0400"; path = dotSsh "id_ed25519.pub";
owner = "user";
}; };
"ssh-unexplrd" = { "ssh-unexplrd" = {
path = "/home/user/.ssh/id_unexplrd_ed25519"; inherit (sshKey) mode owner;
mode = "0400"; path = dotSsh "id_unexplrd_ed25519";
owner = "user";
}; };
"ssh-unexplrd.pub" = { "ssh-unexplrd.pub" = {
path = "/home/user/.ssh/id_unexplrd_ed25519.pub"; inherit (sshKey) mode owner;
mode = "0400"; path = dotSsh "id_unexplrd_ed25519.pub";
owner = "user";
}; };
"ssh-uni" = { "ssh-uni" = {
path = "/home/user/.ssh/id_uni_ed25519"; inherit (sshKey) mode owner;
mode = "0400"; path = dotSsh "id_uni_ed25519";
owner = "user";
}; };
"ssh-uni.pub" = { "ssh-uni.pub" = {
path = "/home/user/.ssh/id_uni_ed25519.pub"; inherit (sshKey) mode owner;
mode = "0400"; path = dotSsh "id_uni_ed25519.pub";
owner = "user";
}; };
}; };
}; };

View File

@ -4,27 +4,22 @@
pkgs, pkgs,
... ...
}: let }: let
sopSec = config.sops.secrets; inherit (config.sops) secrets;
secrets = inputs.mysecrets; inherit (inputs) mysecrets;
in { in {
nix.settings.trusted-users = ["user"]; nix.settings.trusted-users = ["user"];
users.mutableUsers = false; users.mutableUsers = false;
users.users = { users.users = {
user = { user = {
hashedPasswordFile = sopSec."user-password-hashed".path; hashedPasswordFile = secrets."user-password-hashed".path;
# passwordFile = config.sops.secrets.user-password.path;
isNormalUser = true;
extraGroups = ["wheel" "video" "libvirtd" "dialout"]; extraGroups = ["wheel" "video" "libvirtd" "dialout"];
isNormalUser = true;
shell = pkgs.fish; shell = pkgs.fish;
openssh.authorizedKeys.keyFiles = [ openssh.authorizedKeys.keyFiles = map (f: "${mysecrets}/ssh/user/${f}") [
"${secrets}/ssh/id_ed25519_sarien_user.pub" "id_dunamis_ed25519.pub"
"${secrets}/ssh/id_ed25519_eldrid_user.pub" "id_eldrid_ed25519.pub"
"id_sarien_ed25519.pub"
]; ];
}; };
# work = {
# isNormalUser = true;
# extraGroups = ["video"];
# shell = pkgs.nushell;
# };
}; };
} }

View File

@ -1,8 +1,4 @@
{ {inputs, ...}: let
config,
inputs,
...
}: let
inherit (inputs) mysecrets; inherit (inputs) mysecrets;
# TODO: stop relying on networking.hostName # TODO: stop relying on networking.hostName
hostname = "sarien"; hostname = "sarien";