Cannot Get Sops Service to start

I am having an issue where I cannot get the sops service to start. I can encrypt & decrypt using sops on the cli but the service won’t start for me.

{
  description = "Laptop configuration";

  inputs = {
    # NixOS official package source, using the nixos-24.11 branch here
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";

    # Home Manager
    home-manager = {
      url = "github:nix-community/home-manager/release-24.11";
      inputs.nixpkgs.follows = "nixpkgs";  # Follows stable nixpkgs by default
    };

    # Add agenix as an input
    agenix = {
      url = "github:ryantm/agenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };

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

    # Add PIA
    pia = {
      url = "github:Fuwn/pia.nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = { self, nixpkgs, home-manager, agenix, pia, sops-nix, ... }@inputs: {
    # Please replace nixos with your hostname
    nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        ./configuration.nix
        agenix.nixosModules.age
        pia.nixosModules."x86_64-linux".default
        sops-nix.nixosModules.sops  # System-wide sops

        home-manager.nixosModules.home-manager
        {
          home-manager.sharedModules = [
            sops-nix.homeManagerModules.sops
          ];
        }
        # Add agenix CLI using the system variable
        {
          environment.systemPackages = [ agenix.packages.x86_64-linux.default ];
        }
      ];
    };
  };
}

Output of rebuild

🕙 22:28:21 zsh ❯ sudo nixos-rebuild switch

warning: updating lock file '/home/martin/.dotfiles/nix/configuration/flake.lock':
• Updated input 'sops-nix/nixpkgs':
    follows 'nixpkgs'
  → 'github:NixOS/nixpkgs/1128e89fd5e11bb25aedbfc287733c6502202ea9?narHash=sha256-3ebRdThRic9bHMuNi2IAA/ek9b32bsy8F5R4SvGTIog%3D' (2025-02-13)
building the system configuration...
updating GRUB 2 menu...
Warning: os-prober will be executed to detect other bootable partitions.
Its output will be used to detect bootable binaries on them and create new boot entries.
lsblk: /dev/mapper/no*[0-9]: not a block device
lsblk: /dev/mapper/raid*[0-9]: not a block device
lsblk: /dev/mapper/disks*[0-9]: not a block device
activating the configuration...
setting up /etc...
reloading user units for lightdm...
reloading user units for martin...
restarting sysinit-reactivation.target
the following new units were started: libvirtd.service

When I try and switch in home manager it also says that sops doesnt exist?

martin in ~/.dotfiles/nix/configuration  437MiB/11GiB with /run/current-system/sw/bin/zsh took 11s 
🕙 22:37:25 zsh ❯ home-manager switch         
error:
       … while evaluating the attribute 'activationPackage'
         at /home/martin/.nix-defexpr/channels/home-manager/modules/default.nix:1:1164:
       … while evaluating a branch condition
         at /nix/store/9xr4v5kw14aqjg77nqfdspfm2fs2m786-source/lib/lists.nix:126:9:
          125|       fold' = n:
          126|         if n == len
             |         ^
          127|         then nul

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

       error: The option `sops' does not exist. Definition values:
       - In `/home/martin/.dotfiles/nix/home-manager/home.nix':
           {
             age = {
               keyFile = "/home/martin/.config/sops/age/keys.txt";
             };
             defaultSopsFile = /home/martin/.dotfiles/nix/sops/secrets.yaml;

snippet from home.nix


  # Add sops-nix configuration
  sops = {
    defaultSopsFile = ../sops/secrets.yaml;
    age.keyFile = "${config.home.homeDirectory}/.config/sops/age/keys.txt";
  };

If anyone can clear up the issue that would be great or if there is a workaround to using sops with home manager?

Is there a reason why you have both sops-nix and agenix in your inputs/modules?

Are you using home-manager stand alone or as a module? I get the feeling that you do both?

For the system configuration I don‘t see any sops configuration (might be in your configuration.nix but hard to tell) so I suspect that is why it is not doing anything. So I would start with that.

Thanks, it was how I was using home-manager. Have finally resolved. I wasn’t aware that I was using it both ways and it was causing issues.