Mic92 / sops-nix

Atomic secret provisioning for NixOS based on sops
MIT License
1.57k stars 141 forks source link

error: attribute 'placeholder' missing #498

Open pcboy opened 7 months ago

pcboy commented 7 months ago

I'm trying to use the sops-nix placeholders in my nixOS flake and this is strangely failing.

In my home.nix I correctly import the sops-nix home manager module with:

  imports = [
    inputs.sops-nix.homeManagerModules.sops
  ];

  sops = {
    defaultSopsFile = ./secrets/secrets.yaml;
    age.keyFile = "/home/pcboy/.config/sops/age/keys.txt";
    secrets."OPENAPI_KEY" = {};
  };

Then if I'm trying to use the placeholder/template system:

  sops.templates."ollama-config".content = ''
    {
      "models": [
        {
          "title": "OpenAI (gpt 3.5)",
          "provider": "openai",
          "apiKey": "${config.sops.placeholder.OPENAPI_KEY}",
          "model": "gpt-3.5-turbo-0125"
        },
      ]
    }
  '';

I get this:

error:
       … while calling the 'head' builtin

         at /nix/store/818hgwlhx8ygjilaj89za2nyfff6d8aj-source/lib/attrsets.nix:960:11:

          959|         || pred here (elemAt values 1) (head values) then
          960|           head values
             |           ^
          961|         else

       … while evaluating the attribute 'value'

         at /nix/store/818hgwlhx8ygjilaj89za2nyfff6d8aj-source/lib/modules.nix:809:9:

          808|     in warnDeprecation opt //
          809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          810|         inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'placeholder' missing

       at /nix/store/ckarwy9k1k9qz5nz00mihhhr7q8cnq36-source/home.nix:192:24:

          191|           "provider": "openai",
          192|           "apiKey": "${config.sops.placeholder."OPENAPI_KEY"}",
             |                        ^
          193|           "model": "gpt-3.5-turbo-0125"

I also tried to use only the nixOS sops-nix module (instead of the HM one) and use the placeholders, same error.
What am I doing wrong?

I'm on sops-nix from 'github:Mic92/sops-nix/ffed177a9d2c685901781c3c6c9024ae0ffc252b' (2024-02-18)

anasinnyk commented 7 months ago

I have the same issue. I saw a code and as I understand templates support only for nixOs Modules, not for home-manager modules, I hope yet.

dixslyf commented 7 months ago

Indeed. Templates are only available in the NixOS module. There is an existing issue for template support for the HM module: https://github.com/Mic92/sops-nix/issues/423.

Mic92 commented 6 months ago

I think the python script should be moved into the go code than it will be available on all platforms as it is.