Pinning packages in modules using flakes

Hello all,
I am just starting out in NixOs, and I am trying to set up prowlarr + flaresolverr. Flaresolverr is currently broken, and in the github issue a NUR repo is linked that has apparently fixed it. However, I cannot seem to get it to work. I have added it to my flake.nix as follows:

{
  description = "NixOS configuration";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    nur = {
      url = "github:nix-community/NUR";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = inputs@{ self, nixpkgs, nur, home-manager, ... }: {
    nixosConfigurations = {
      nixos = nixpkgs.lib.nixosSystem {
        specialArgs = { inherit inputs; };
        system = "x86_64-linux";
        modules = [
          ./configuration.nix
          nur.modules.nixos.default
          home-manager.nixosModules.home-manager
          {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.jack = import ./home.nix;
          }
        ];
      };
    };
  };
}

I want to use this in a module /etc/nixos/mods/vpncontainer.nix that is used in my /etc/nixos/configuration.nix
Can anyone point me in the right direction?

Based on this comment and your current setup, it seems you should only need to add a snippet like this to /etc/nixos/mods/vpncontainer.nix

{ pkgs, ... }:

{
  services.flaresolverr.package = pkgs.nur.repos.xddxdd.flaresolverr-21hsmw;
}

Along with the rest of the configuration for the service

{ config, lib, pkgs, ... }:
{
  environment.etc.openvpn.source = "${pkgs.update-resolv-conf}/libexec/openvpn";
  services.openvpn.servers = {
    torrentvpn = {
      config = ''
        config ...
        auth-user-pass ...
      ''; 
      # updateResolvConf = true; needs to be off otherwise tailscale fucks up
    };
  };

  networking = {
    nat = {
      enable = true;
      internalInterfaces = ["ve-+"];
      externalInterface = "tun0";
    };
    networkmanager.unmanaged = [ "interface-name:ve-*" ];
  };

  containers.vpn = {
    autoStart = true;
  
    privateNetwork = true; # needed for vpn 
    hostAddress = ...
    localAddress = ...
    
    # bindMounts = {
    # "/etc/nixos/openvpn" = { # path in container
    #   hostPath = "/etc/nixos/openvpn"; # path in host
    #   isReadOnly = true;
    #   };
    # # jellyfin lib here
    # };

    config = { config, lib, pkgs, ... }: 
    {
      environment.systemPackages = with pkgs; [
        kitty
        neovim
        fastfetch
      ];
      # stupid fix
      services.prowlarr = {
        enable = true;
        openFirewall = true;
      };
      services.flaresolverr = {
        enable = true;
        package = pkgs.nur.repos.xddxdd.flaresolverr-21hsmw;
        openFirewall = true;
      };
      services.radarr = {
        enable = true;
        openFirewall = true;
      };
      services.sonarr = {
        enable = true;
        openFirewall = true;
      };

      environment.etc = { # grosshack
        "resolv.conf".text = "nameserver 10.96.0.1\n";
      };

      networking = {
        # Workaround for bug https://github.com/NixOS/nixpkgs/issues/162686
        useHostResolvConf = lib.mkForce false;

        firewall = {
          enable = true;
          allowedTCPPorts = [ 80 ];
        };
      };

      users.extraUsers.vpnuser = {
        isNormalUser = true;
        uid = 1000;
      };
    };
  };
}

thanks for the fast reply!
sadly nixos thinks otherwise:

error: attribute 'nur' missing
       at /nix/store/y98bigzpblkpmkf2p3h3y7307fn2xwzp-source/mods/vpncontainer.nix:52:19:
           51|         enable = true;
           52|         package = pkgs.nur.repos.xddxdd.flaresolverr-21hsmw;
             |                   ^
           53|         openFirewall = true;
       Did you mean one of nrr, nurl, nut, nuv or nux?

Try dropping the pkgs in front of nur? As far as I can tell your passing nur as an input to configuration.nix side by side with pkgs, not nested under pkgs.

Or you might need to refer to inputs explicitly: inputs.nur.repos...

( I’m fairly new to nix, so take this with a grain of salt)

{ pkgs, ... }:

{
  # services.flaresolverr.package = pkgs.nur.repos.xddxdd.flaresolverr-21hsmw;
  services.flaresolverr.package = nur.repos.xddxdd.flaresolverr-21hsmw;
  # or
  services.flaresolverr.package = inputs.nur.repos.xddxdd.flaresolverr-21hsmw;
}

Hmmm, based on your flake.nix, this shouldn’t be the case

Importing the NUR module should be applying their overlay (as shown here), and this is even shown in their Flake example

Could you run nixos-option nixpkgs.overlays and check the value to see if it’s being properly applied?

nixos-option nixpkgs.overlays yields:

Value:
  [
    <function>
  ]

Default:
  [ ]

Type:
  list of (nixpkgs overlay)

Description:
  List of overlays to apply to Nixpkgs.
  This option allows modifying the Nixpkgs package set accessed through the `pkgs` module argument.
  
  For details, see the [Overlays chapter in the Nixpkgs manual](https://nixos.org/manual/nixpkgs/stable/#chap-overlays).
  
  If the {option}`nixpkgs.pkgs` option is set, overlays specified using `nixpkgs.overlays` will be applied after the overlays that were already included in `nixpkgs.pkgs`.

Example:
  {
    _type = "literalExpression";
    text = ''
      [
        (self: super: {
          openssh = super.openssh.override {
            hpnSupport = true;
            kerberos = self.libkrb5;
          };
        })
      ]
    '';
  }

Declared by:
  /nix/store/4m21g6b3bq78vn5skaxjmqwg7fnir87j...

both make nix angry, option one:

error: undefined variable 'inputs'
       at /nix/store/q3p4yhsx8ajv8iv79if31nlhi2vv6ijl-source/mods/vpncontainer.nix:67:21:
           66|           enable = true;
           67|           package = inputs.nur.repos.xddxdd.flaresolverr-21hsmw;
             |                     ^
           68|           openFirewall = true;

option two:

 error: undefined variable 'nur'
       at /nix/store/iyxlp6n49jhhq03lqkj4mw1pxf7vg84v-source/mods/vpncontainer.nix:67:21:
           66|           enable = true;
           67|           package = nur.repos.xddxdd.flaresolverr-21hsmw;
             |                     ^
           68|           openFirewall = true;
> 

Anyone have suggestions?, still struggling with this :frowning:

You didn’t add it as a module arg at the top of your file, and you also need to pass it in via specialArgs argument to nixosSystem.

# configuration.nix
{
  description = "NixOS configuration";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    nur = {
      url = "github:nix-community/NUR";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = inputs@{ self, nixpkgs, nur, home-manager, ... }: {
    nixosConfigurations = {
      nixos = nixpkgs.lib.nixosSystem {
        specialArgs = { inherit inputs; };
        system = "x86_64-linux";
        modules = [
          ./configuration.nix
          nur.modules.nixos.default
          home-manager.nixosModules.home-manager
          {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.jack = import ./home.nix;
          }
        ];
      };
    };
  };
}

moved on to a different error now!

error: attribute 'repos' missing
       at /nix/store/p2nkc8mrpzmn515xj4qj4kyd0a5158v4-source/mods/vpncontainer.nix:105:21:
          104|           enable = true;
          105|           package = inputs.nur.repos.xddxdd.flaresolverr-21hsmw;
             |                     ^
          106|           openFirewall = true;