home-manager на rydiwo падал при активации:
ln: failed to create symbolic link
'/home/oqyude/.config/opencode/opencode.json': Permission denied
→ home-manager-oqyude.service: status=1/FAILURE, домашняя активация не
применялась.
Причина: sops-nix создаёт отсутствующие каталоги-родители секретов от root
(0755 root:root) и не меняет владельца уже существующих. На rydiwo секреты
opencode появились раньше home-manager (13.10 против 06.11), поэтому
~/.config/opencode и ~/.local/share/opencode остались root:root. На sapphira
те же каталоги создал home-manager (как пользователь) — там не сломано.
sops-nix не умеет менять владельца каталога-родителя, поэтому делаем это в
активации системы (root), снипет после 'users' — до старта
home-manager-<user>.service. chown/install через '|| echo': у activate
скрипта ERR-trap, и падение сделало бы активацию проваленной при уже
переключённой системе.
Заодно в home/modules/opencode-desktop.nix: timeout 600/900 на прогрев
плагина и npx-кеша — зависшая загрузка не должна держать активацию
(и пересборку) намертво.
207 lines
8.0 KiB
Nix
207 lines
8.0 KiB
Nix
{
|
|
config,
|
|
xlib,
|
|
lib,
|
|
...
|
|
}:
|
|
let
|
|
user = "${xlib.device.username}";
|
|
userGroup = config.users.users."${user}".group;
|
|
|
|
# sops secret factory: name == key by default, owner/group default to root.
|
|
# `format` and `sopsFile` default to yaml + defaultSopsFile, matching every
|
|
# pre-existing caller.
|
|
mkSecret =
|
|
{
|
|
path,
|
|
mode,
|
|
key ? null,
|
|
owner ? null,
|
|
group ? null,
|
|
format ? "yaml",
|
|
sopsFile ? null,
|
|
}:
|
|
{
|
|
inherit format path mode;
|
|
}
|
|
// lib.optionalAttrs (key != null) { inherit key; }
|
|
// lib.optionalAttrs (owner != null) { inherit owner; }
|
|
// lib.optionalAttrs (group != null) { inherit group; }
|
|
// lib.optionalAttrs (sopsFile != null) { inherit sopsFile; };
|
|
|
|
# default owner = device user
|
|
mkUserSecret =
|
|
args:
|
|
mkSecret (
|
|
args
|
|
// {
|
|
owner = user;
|
|
group = userGroup;
|
|
}
|
|
);
|
|
in
|
|
{
|
|
users = {
|
|
mutableUsers = false;
|
|
users = {
|
|
"${user}" = {
|
|
name = "${user}";
|
|
isNormalUser = true;
|
|
group = "users";
|
|
# Pinned, not left to NixOS' nextfree logic: the ntfs3/exfat mount
|
|
# helpers (lib/xlib/helpers.nix) bake xlib.device.uid into their mount
|
|
# options, so normally both sides agree and NTFS/exFAT files do not
|
|
# show up as owned by `nobody`. NixOS has no per-user `gid` option —
|
|
# the primary group id comes from `group` above.
|
|
#
|
|
# sapphira is the one exception, and only until its filesystem gets
|
|
# migrated: /var/lib/nixos/uid-map still reserves 1000 for the
|
|
# long-removed `yuyus` and NixOS never renumbers an existing user, so
|
|
# the live `oqyude` there is uid 1001. Without this branch a rebuild
|
|
# would rewrite the user to 1000 while every file is still owned by
|
|
# 1001. The cost: the exFAT mounts on sapphira still get uid=1000 from
|
|
# xlib.device.uid, so that user cannot write to /mnt/archive or
|
|
# /mnt/mobile until the id question is settled.
|
|
# TODO: delete this branch once sapphira is migrated to 1000.
|
|
uid = if xlib.device.hostname == "sapphira" then 1001 else xlib.device.uid;
|
|
description = "Jor Oqyude";
|
|
hashedPasswordFile = config.sops.secrets.hashed_password.path; # hashed_password
|
|
homeMode = "700";
|
|
home = "/home/${user}";
|
|
# Linger keeps `user@<uid>.service` (the systemd user manager) alive
|
|
# across logouts, so user services like opencode-web survive when no
|
|
# SSH/login session is active. Without this the service is torn down
|
|
# together with the user manager on the last session close.
|
|
linger = true;
|
|
extraGroups = [
|
|
"audio"
|
|
"disk"
|
|
"gamemode"
|
|
"networkmanager"
|
|
"pipewire"
|
|
"wheel"
|
|
"libvirtd"
|
|
"qemu-libvirtd"
|
|
];
|
|
openssh.authorizedKeys.keys = [
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKduJia+unaQQdN6X5syaHvnpIutO+yZwvfiCP4qKQ/P"
|
|
];
|
|
};
|
|
};
|
|
};
|
|
|
|
# Каталоги-родители секретов opencode должны принадлежать ПОЛЬЗОВАТЕЛЮ.
|
|
#
|
|
# sops-nix создаёт отсутствующие каталоги-родители секретов от root
|
|
# (0755 root:root) и НЕ меняет владельца уже существующих. На rydiwo
|
|
# секреты opencode появились раньше, чем home-manager (13.10 против
|
|
# 06.11), поэтому ~/.config/opencode и ~/.local/share/opencode остались
|
|
# root:root — и home-manager не смог создать в них свои файлы:
|
|
# ln: failed to create symbolic link
|
|
# '/home/oqyude/.config/opencode/opencode.json': Permission denied
|
|
# → home-manager-oqyude.service падал (status=1/FAILURE), домашняя
|
|
# активация не применялась. На sapphira те же каталоги создал
|
|
# home-manager (как пользователь) — там sops-nix ничего не сломал, но
|
|
# тот же класс граблей повторится, если каталог когда-нибудь удалят.
|
|
#
|
|
# sops-nix не умеет менять владельца каталога-родителя, поэтому делаем
|
|
# это в активации системы (root). Порядок неважен: каталог либо уже
|
|
# создан sops-никсом (тогда chown его чинит), либо создаётся здесь
|
|
# (тогда sops-nix увидит существующий каталог и не станет менять
|
|
# владельца). Snippet идёт после "users" — до старта
|
|
# home-manager-<user>.service, который запускает switch-to-configuration.
|
|
#
|
|
# chown/install идут через `|| echo`: activate скрипт имеет ERR-trap и
|
|
# завершился бы с `_status=1` (активация объявлена проваленной), хотя
|
|
# система уже переключена.
|
|
system.activationScripts.opencodeSecretDirs = {
|
|
text = ''
|
|
for dir in \
|
|
${xlib.dirs.user-home}/.config/opencode \
|
|
${xlib.dirs.user-home}/.local/share/opencode
|
|
do
|
|
install -d -m 0755 "$dir" || echo "warning: не удалось создать $dir" >&2
|
|
chown ${user}:${userGroup} "$dir" || echo "warning: не удалось сменить владельца $dir" >&2
|
|
done
|
|
'';
|
|
deps = [ "users" ];
|
|
};
|
|
|
|
sops = {
|
|
age = {
|
|
sshKeyPaths = [
|
|
"/etc/ssh/id_ed25519"
|
|
];
|
|
};
|
|
defaultSopsFile = ../secrets/default.yaml;
|
|
secrets = {
|
|
hashed_password = {
|
|
neededForUsers = true;
|
|
format = "yaml";
|
|
key = "hashed_password";
|
|
};
|
|
age_key_private = mkUserSecret {
|
|
path = "${xlib.dirs.user-home}/.config/sops/age/keys.txt";
|
|
mode = "0600";
|
|
};
|
|
# opencode web server creds + Gemini API key.
|
|
# Decrypted as a single dotenv file (no `key`) and consumed by the
|
|
# systemd user unit opencode-web as EnvironmentFile.
|
|
# Source: secrets/opencode.env (encrypted, see sops/age below).
|
|
# Path is shared with home/modules/opencode.nix via xlib.dirs so the
|
|
# sops materialization and the systemd EnvironmentFile can never
|
|
# silently desync.
|
|
opencode_server = mkUserSecret {
|
|
path = xlib.dirs.opencode-server-env;
|
|
mode = "0600";
|
|
format = "dotenv";
|
|
sopsFile = ../secrets/opencode.env;
|
|
};
|
|
# opencode provider credentials (XDG_DATA_HOME/opencode/...).
|
|
# Both files are read by opencode at startup to populate the providers
|
|
# list. Mirror of ~/.local/share/opencode/ on the workstation.
|
|
# key = "" → decrypt the WHOLE file as-is (the JSON has no top-level
|
|
# field named after the secret; it IS the secret).
|
|
opencode_auth = mkUserSecret {
|
|
path = "${xlib.dirs.user-home}/.local/share/opencode/auth.json";
|
|
mode = "0600";
|
|
format = "json";
|
|
sopsFile = ../secrets/opencode-auth.json;
|
|
key = "";
|
|
};
|
|
opencode_account = mkUserSecret {
|
|
path = "${xlib.dirs.user-home}/.local/share/opencode/account.json";
|
|
mode = "0600";
|
|
format = "json";
|
|
sopsFile = ../secrets/opencode-account.json;
|
|
key = "";
|
|
};
|
|
ssh_key_private = mkUserSecret {
|
|
path = "${xlib.dirs.user-home}/.ssh/id_ed25519";
|
|
mode = "0600";
|
|
};
|
|
ssh_key_public = mkUserSecret {
|
|
path = "${xlib.dirs.user-home}/.ssh/id_ed25519.pub";
|
|
mode = "0655";
|
|
};
|
|
ssh_key_private_root = mkSecret {
|
|
key = "ssh_key_private";
|
|
path = "/root/.ssh/id_ed25519";
|
|
mode = "0600";
|
|
};
|
|
ssh_key_public_root = mkSecret {
|
|
key = "ssh_key_public";
|
|
path = "/root/.ssh/id_ed25519.pub";
|
|
mode = "0655";
|
|
};
|
|
ssh_key_public_host = mkSecret {
|
|
key = "ssh_key_public";
|
|
path = "/etc/ssh/id_ed25519.pub";
|
|
mode = "0655";
|
|
};
|
|
};
|
|
};
|
|
|
|
# fileSystems."/etc/ssh".neededForBoot = true;
|
|
}
|