Welcome to the forums!
As you noted, it will “work” in that you can dynamically create an nn.Linear with an input dimension that varies with x. But this necessarily changes the shape of the weight tensor, so, once saved, it will not match all of your data points.
I think the typical solution is to make a nn.Linear that matches the max x value of your data and pad the small data points with zeros.