Sops modules not found

I’m trying to use sops-nix according to the instructions at GitHub - Mic92/sops-nix: Atomic secret provisioning for NixOS based on sops. All goes well until step 5. When I add <sops-nix/modules/sops> to the import, it complains upon rebuild with file 'sops-nix/modules/sops' was not found in the Nix search path.

I went over the instructions a few times and don’t think I
missed anything. I have, in my flake.nix inputs section

sops-nix.url = "github:Mic92/sops-nix";

and the outputs

  outputs = { self, nixpkgs, home-manager, sops-nix, ... } @inputs: 
    let
      system = "x86_64-linux";
      lib = nixpkgs.lib;
      pkgs = nixpkgs.legacyPackages.${system};
    in {
    nixosConfigurations."nixos" = lib.nixosSystem {
        inherit system;
        specialArgs = { inherit inputs; };
        modules = [ 
          ./configuration.nix
          sops-nix.nixosModules.sops
        ];
      };

I’d appreciate some help. Thanks.

Edit: In the vimjoyer video referenced by the sops-nix instructions, it suggests using inputs.sops-nix.nixosModules.sops in the imports section. That failed with a different error:

The option `sops.gnupg.home' in `/nix/store/asymc3nsl739p1wwr0w6xbjnqs3qb94p-source/flake.nix' is already declared in `/nix/store/za3nda9aii5vdryyl9v38idldwxpjcaq-source/configuration.nix'
1 Like

The <...> syntax in Nix is for “find this in the Nix search path”. That snippet is intended for if you install sops-nix using a nix-channel (not using flakes).

The modules = [ ... sops-nix.nixosModules.sops ] should already be sufficient for adding the module to your configuration.

Thanks. If I try as use suggest I get a sops-nix undefined variable error. If I change it to inputs.sops-nix.nixosModules.sops, I get the error

The option `sops.gnupg.home' in `/nix/store/asymc3nsl739p1wwr0w6xbjnqs3qb94p-source/flake.nix' is already declared in `/nix/store/za3nda9aii5vdryyl9v38idldwxpjcaq-source/configuration.nix'

To discuss the Nix code a bit, the line:

outputs = { self, nixpkgs, home-manager, sops-nix, ... } @inputs: 

The { self, sops-nix, ... }@inputs part means that both sops-nix and inputs.sops-nix refer to the same value.

“The option … is already declared” suggests to me that you’re importing sops-nix.nixosModules.sops twice. – You should import it either in the modules that you’re passing to lib.nixosSystem, or in your configuration.nix, but not in both.

It suggests that to me as well, but this is everything I have related to sops in my configs.

flake.nix
8:    sops-nix.url = "github:Mic92/sops-nix";
9:    sops-nix.inputs.nixpkgs.follows = "nixpkgs";
25:  outputs = { self, nixpkgs, home-manager, sops-nix, ... } @inputs:
36:          sops-nix.nixosModules.sops

configuration.nix
12:      inputs.sops-nix.nixosModules.sops
28:      #keyFile = "/var/lib/sops-nix/key.txt";

Right, so delete one of those.

Either remove sops-nix.nixosModules.sops from your flake.nix, or remove the inputs.sops-nix.nixosModules.sops from your configuration.nix.

I had misunderstood the language then. I thought the output in the flake.nix was passed as input to the configuration.nix file.

Thank you so much. I removed the line from configuration.nix and it built fine. Onward to the next step :slight_smile: