Hi there, I have the following files being imported in a chain:
flake.nix → home/rembot/default.nix → modules/default.nix → git/default.nix
(rembot = host, and the other files are via home-manager.)
What I am trying to do is pass a “secrets” reference down this chain. I am reading a json file with some sensitive info.
I am working from the “git-crypt” section of this article
So… I am going to post the relevant code snippets with a little context pre and post.
flake.nix
so here I am defining “secrets” reading from a JSON file. Then via “sepcialArgs”, I am passing the secrets reference.
outputs =
inputs@{ self, nixpkgs, nixvim, home-manager, nixos-hardware, nur, ... }:
let
nixpkgsConfig = { overlays = [ ]; };
secrets =
builtins.fromJSON (builtins.readFile "${self}/secrets/secrets.json");
in {
nixosConfigurations = {
# Fulrther down, to myhost:
# rembot = desktop hostname
rembot = nixpkgs.lib.nixosSystem {
specialArgs = { inherit inputs secrets; };
system = "x86_64-linux";
modules = [
home-manager.nixosModules.home-manager
{
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.users.dustin = {
imports =
[ ./home/rembot ];
};
/home/rembot
Here I am passing in “secrets” so the context (if I understand correctly) continues with the imports.
{ config, inputs, pkgs, secrets, ... }: {
# Home Manager needs a bit of information about you and the
# paths it should manage.
home.username = "dustin";
home.homeDirectory = "/home/dustin";
imports = [ ../modules ../modules/gnome ];
…/modules
Nothing crazy, simply adding “secrets”, and the next import.,
{ config, inputs, pkgs, secrets, ... }: {
imports = [
# snip
./git
#snip
];
}
./git/default.nix
here, have secrets coming in, and they try to use a value.
{ pkgs, lib, secrets, ... }:
# let globalconf = import ../../cfg;
#in
{
programs = {
git = {
enable = true;
userName = "${secrets.git.username}";
# snipped
But when I run my rebuild, I am getting:
error: attribute 'secrets' missing
I must be doing something wrong.
Thank you.
Cheers.