ITADN

Throw while nix eval when any secret file is malformed

#349Openn0099 创建于 2025-10-08
N
n0099commented
Suppose we have following NixOS module: ```nix { config, ... }: { users = { mutableUsers = false; users.n0099.hashedPasswordFile = config.age.secrets."users.n0099.hashedPassword".path; }; age.secrets."users.n0099.hashedPassword".file = ./users.n0099.hashedPassword.age; } ``` and the file `users.n0099.hashedPassword.age` is empty or with malformed format that cannot be parsed by age, `nixos-rebuild` will still be happy to eval, build and switch to the new profile. After switch the [`system.activationScripts.agenixInstall`](https://github.com/ryantm/agenix/blob/9edb1787864c4f59ae5074ad498b6272b3ec308d/modules/age.nix#L311) will fail and logging its stderr to `nixos-rebuild`, but it's already too late for this user to do anything for this footgun due to: - `mutableUsers` is disabled so `passwd` won't work - switch to another new profile with roll-backed changes will require root - `sudo` is requiring password of this user, but it's already being unset via `mutableUsers = false` during system activation so any password won't pass - login to root via ssh or tty requires the password of user root but it's also get reset - booting into previous profile in bootloader won't rollback the affect of reset `/etc/passwd` file The only way to recovery user accesses without any existing shell under user `root` is booting to another rescue system with NixOS and using `nixos-enter` to login with root, then fix this age file and `nixos-rebuild` or switch to a new profile with `mutableUsers = true`.
0 条评论